/** ***********************************************************************************
* @file         n808_app.c
* @brief    	国标808协议管理
* @details      主要用来处理808协议内容
* @author       
* @date         2021/5/27
* @copyright    北京高知科技有限公司    
* @version      V1.0
* @attention    无
**************************************************************************************/
#define OSI_LOG_TAG OSI_MAKE_LOG_TAG('8', '0', '0', 'B')

#include "fibo_opencpu.h"
#include "algorithm.h"
#include "files.h"
#include "net_port.h"
#include "gnss_task.h" 
#include "national_data_process.h"
#include "com_lib.h"
#include "fota.h"
#include "vehicle_data_process.h"
#include "bluetooth_app.h"
#include "flash_config.h"
#include "flash_dev.h"
#include "mangpatio.h"
#include "n808_app.h"
#include "qxwz_service.h"
#include "lbs_task.h"
#include "AES.h" 

#define NAT808_SENDTASK_NAME   "808_sendtask"
#define NAT808_RECVTASK_NAME   "808_recvtask"
#define NAT808_OTATASK_NAME    "808_otatask"

static uint8_t	national808_reset_reason = 0;
static uint8_t	national808_auth_reason = 0; 
static uint32_t mangpatio_auth_recv_st = 0;
static uint32_t national808_auth_recv_st = 0;
update_result_t update_t={0};/*升级类型结果*/
uint8_t terminid[6]={0};  /*808终端ID*/
uint16_t appserialNum=0;  /*808流水号*/
wakeup_source_e report_flag = POWER_INIT;  /*休眠唤醒标志*/
net_reset_e  net_rst = NET_RST_INT;  /*修改网络参数重启网络*/
pkekey_dev_t pke_key = {0};
terminal_info_t	taginf = {0},curinf = {0};/*终端参数*/
//gnss_info_struct gnss_info_old={0};
terminal_ota_t terota_handle = {0};/*终端升级操作句柄*/
socket_handle_s socket_handle_1;  /*定义socket handle 可以同时打开6路通道*/
socket_state_t socket_state_1;   /*定义socket 网络状态*/
GaozSemaphoreHandle_t   socket_semaphore_808 = 0;/*网络状态信号量*/
GaozSemaphoreHandle_t   patio_recv_data_mutex = 0; //接收互斥
national_run_state_e national808_runing_st;   /*网络运行的状态*/
national808_netready_e n808_netready;    /*休眠唤醒后网络状态*/
national_response_e national808_response;     /*平台应答的方式*/
national_send_data_e national808_send_data;   /*平台发送数据的状态*/
national_net_data_st_t national808_net_data; /* 发送接收数据的网络状态*/
GaozQueueHandle_t national808_send_patiores_queue; /*发送平台数据应答消息队列*/
GaozQueueHandle_t national808_send_devres_queue; /*发送设备应答消息队列*/
GaozQueueHandle_t national808_ctlock_queue;    /*控锁消息队列*/
GaozQueueHandle_t national808_ctlock_res_queue;    /*控锁异步消息队列*/
GaozQueueHandle_t national808_upgrade_queue; /*升級消息队列*/
national808_ctrllock_e national808_ctlock;   /*控锁状态*/
//static uint32_t national808_set_time_tick;     /*周期上报时间*/
static uint32_t national808_herat_time_tick;     /*心跳上报时间*/
static uint32_t national808_bms_time_tick;		/*BMS数据上报时间*/
national808_data_st_t national808_data_st; /*发送数据缓存的状态*/
static n808_patio_recv_buf_t patio_recv_data;  /*数据接收平台缓存数据*/
static national_808_auth_e n808_auth_sta; /*鉴权状态*/
uint8_t *gerr_code = NULL;
static national808_send_state_e national808_send_state; /*数据重复发送状态*/
static national_808_ip_addr_type_e national_808_ip_addr_t; /*平台地址类型*/
static uint8_t national_808_relay_state;	/*终端继电器状态 0x01 供电导通 0x02 供电断开*/
static national_808_ctrl_infor_t national_808_ctrl_infor; /*平台控制命令消息结构体*/
GaozSemaphoreHandle_t   warmcar_bms_semaphore_808_vehicle = 0;/*WARMCAR BMS数据上传信号量*/

static void national808_socket_semaphore_create(void);
static void national808_socket_semaphore_put(void);
static uint8_t national808_socket_semaphore_get( uint32_t wait_time );
static void national808_create_network_state_cb( void * pv);
static void national808_net_st_check_task(void *param);
static void national808_data_analytic_fun( national_net_res_msg_t *net_res);
//void national808_net_runing_state_set( national_run_state_e  state );
static uint32_t national808_socket_send_data_suc( socket_state_t *state ,uint32_t time );
static uint32_t parse_patio_recv_data( uint8_t *da, uint16_t len );
static int saveserviceloadpara(uint8_t *pDa,uint8_t type,uint8_t *pDa2);
static uint8_t setParafromservice(uint8_t * da, uint16_t len);
static int readTerminalPara(const INT8 *filename);
static uint8_t initTerminalParaAll(uint8_t * ManageID,uint8_t *da,uint16_t *len);
static uint16_t SendRegister(uint8_t *da);
static uint16_t Authentication(uint8_t *da);
static uint16_t SendHeart(uint8_t *da);
static uint16_t generalrespond(national808_net_devres_msg_t *res_msg,uint8_t *da);
static uint16_t rsarespond(national808_net_devres_msg_t *res_msg,uint8_t *da);
static uint16_t qxwzrespond(national808_net_devres_msg_t *res_msg,uint8_t *da);
static uint16_t lockrespond(uint8_t *da, national808_ctrllock_msg_t *res_msg);
//static uint16_t requestrsa(uint8_t *da);
//static uint16_t unregisterfromsys(uint8_t *da);
static uint16_t property(uint8_t *da);
static uint16_t parameter(national808_net_devres_msg_t *res_msg,uint8_t *da);
//static uint16_t rsasecret(uint8_t *da);
static uint16_t msgtranslation(uint8_t *da,uint8_t *txbuf, uint16_t len);
static uint16_t updateresult(update_result_t *upslt,uint8_t *da);
static uint16_t pkekeyrsp(national808_net_devres_msg_t *res_msg, uint8_t *da);
static uint16_t pkekeyupload( uint8_t *da);
static uint16_t querypkekey(uint8_t *da);

void national808_ctrllock_state_set( national808_ctrllock_e  state );
static uint32_t national808_net_ip_addr_check( char *ip );

static uint32_t gzlable_check_flash_parameters( void );
static void national808_net_control_state_check( void );
static uint16_t network_data_transmission( uint8_t *da );
static uint16_t network_data_engine_start_transmission( uint8_t *da );
static uint16_t network_data_fault_code_transmission( uint8_t *da );
static uint16_t network_data_maintenance_infor_transmission( uint8_t *da );
static uint16_t network_data_bms_infor_transmission( uint8_t *da );
static uint16_t network_data_seed_infor_transmission( uint8_t *da );
static uint16_t network_data_adas_infor_transmission( uint8_t *da );

static uint32_t national808_decrypt_package( uint8_t * pDa, uint16_t *len, uint16_t serailNum );
#if( USER_AES_ENCRYPT_N800 == 1 )
static uint32_t national808_encrypt_package( uint8_t *pDa, uint16_t *len, uint16_t serailNum );
#endif
static uint32_t national808_decrypt_package_shell( uint8_t* pDa, uint16_t* len );
#if( USER_AES_ENCRYPT_N800 == 1 )
static uint32_t national808_encrypt_package_shell( uint8_t* pDa, uint16_t* len );
#endif

/** ****************************************************************************
* @remarks       national_808_auth_e n808_authsta_get( void )
* @brief         
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     
*******************************************************************************/
national_808_auth_e n808_authsta_get( void )
{
	return  n808_auth_sta;
}
/** ****************************************************************************
* @remarks       void n808_authsta_set( national_808_auth_e sta )
* @brief         
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     
*******************************************************************************/
void n808_authsta_set( national_808_auth_e sta )
{
	n808_auth_sta = sta;
}
/** ****************************************************************************
* @remarks       wakeup_source_e wakeup_source_get( void )
* @brief         
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     
*******************************************************************************/
wakeup_source_e wakeup_source_get( void )
{
	return  report_flag;
}
/** ****************************************************************************
* @remarks       void wakeup_source_set( wakeup_source_e flag )
* @brief         
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     
*******************************************************************************/
void wakeup_source_set( wakeup_source_e flag )
{
	report_flag = flag;
}
/** ****************************************************************************
* @remarks       void patio_recv_data_mutex_create( void )
* @brief         接收平台数据互斥体
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     在系统启动后进行创建
*******************************************************************************/
static void patio_recv_data_mutex_create( void )
{
    /*创建任务互斥体*/
    patio_recv_data_mutex = gaoz_mutex_create();
    if( patio_recv_data_mutex == 0 )
    {
        while(1); /*创建失败*/
    }
}
/** ****************************************************************************
* @remarks       static void national808_socket_semaphore_create(void)
* @brief         网络状态信号创建
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void national808_socket_semaphore_create(void)
{
    socket_semaphore_808 = gaoz_sem_new(0);
    if( socket_semaphore_808 == 0 )
    {
        while(1);
    }
}

/** ****************************************************************************
* @remarks       static uint8_t national808_socket_semaphore_get( uint32_t wait_time )
* @brief         获取网络回调状态的信号量
* @param[in]     wait_time 等待信号的时间 单位S
* @param[out]    无
* @return        1 等待信号成功  ， 0 等待信号失败，超时等待
* @attention     无
*******************************************************************************/
static uint8_t national808_socket_semaphore_get( uint32_t wait_time )
{
    if(socket_semaphore_808 == 0)
    {
        national808_socket_semaphore_create();
    }
    if( gaoz_sem_try_wait( socket_semaphore_808, wait_time ) == true ) //等待回应信号量
    {
        return 1;
    }
    else
    {   
        return 0;
    }
}

/** ****************************************************************************
* @remarks       void national808_socket_semaphore_put(void)
* @brief         释放信号
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void national808_socket_semaphore_put(void)
{
    if( socket_semaphore_808 != 0 )
    {
        gaoz_sem_signal( socket_semaphore_808 );
    }
}

/** ****************************************************************************
* @remarks        vehicle_info_report_semaphore_put(void)
* @brief         车辆信息直接上报
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
 void vehicle_info_report_semaphore_put(void)
{
    national808_net_ctrl_infor_set( TER_RUNING_QUERY_DATA_ACTIVE );
}

/** ****************************************************************************
* @remarks       void national808_auth_reason_set(uint8_t reason)
* @brief         鉴权原因设置
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
void national808_auth_reason_set(uint8_t reason)
{
	national808_auth_reason  = reason ;
	gaoz_log_debug_printf(INFOR_MODE,"800b", "national808 auth reason set= [%d] \r\n",national808_auth_reason);
}

/** ****************************************************************************
* @remarks       uint8_t national808_auth_reason_get(void)
* @brief         鉴权原因获取
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
uint8_t national808_auth_reason_get(void)
{
	return national808_auth_reason;
}

/** ****************************************************************************
* @remarks       uint8_t national808_auth_reason_clear(void)
* @brief         清除鉴权重启原因
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
uint8_t national808_auth_reason_clear(void)
{
	national808_auth_reason_set(0);

	if(national808_reset_reason)
	{
		national808_reset_reason = 0;
		reset_reason_clear();
		 gaoz_log_debug_printf(INFOR_MODE,"800b", "national808 reset reason clear \r\n",0);
	}

	 gaoz_log_debug_printf(INFOR_MODE,"800b", "national808 auth reason clear \r\n",0);
}



/** ****************************************************************************
* @remarks       static void warmcar_bms_semaphore_create(void)
* @brief         warmcar bms信号量创建
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void warmcar_bms_semaphore_create(void)
{
    warmcar_bms_semaphore_808_vehicle = gaoz_sem_new(0);
    if( warmcar_bms_semaphore_808_vehicle == 0 )
    {
        while(1);
    }
}
 

/** ****************************************************************************
* @remarks       static uint8_t warmcar_bms_semaphore_get( uint32_t wait_time )
* @brief         获取bms信号量
* @param[in]     wait_time 等待信号的时间 单位S
* @param[out]    无
* @return        1 等待信号成功  ， 0 等待信号失败，超时等待
* @attention     无
*******************************************************************************/
static uint8_t warmcar_bms_semaphore_get( uint32_t wait_time )
{
    if(warmcar_bms_semaphore_808_vehicle == 0)
    {
        warmcar_bms_semaphore_create();
    }
    if( gaoz_sem_try_wait( warmcar_bms_semaphore_808_vehicle, wait_time ) == true ) //等待回应信号量
    {
        return 1;
    }
    else
    {   
        return 0;
    }
}

/** ****************************************************************************
* @remarks       void warmcar_bms_semaphore_put(void)
* @brief         释放信号
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
 void warmcar_bms_semaphore_put(void)
{
    if( warmcar_bms_semaphore_808_vehicle != 0 )
    {
        gaoz_sem_signal( warmcar_bms_semaphore_808_vehicle );
    }
}



/** ****************************************************************************
* @remarks       uint32_t national808_socket_send_data_suc( socket_state_t * state ,uint32_t time )
* @brief         等待发送数据成功状态
* @param[in]     *state 网络状态 数据地址
* @param[in]     time 等待的时间
* @param[out]    无
* @return        pdPASS，pdFAIL
* @attention     无
*******************************************************************************/
static uint32_t national808_socket_send_data_suc( socket_state_t *state ,uint32_t time )
{
	uint32_t ret = pdFAIL; 
    if( national808_socket_semaphore_get( time ) == 1 )
    {
    	/******************判断网络数据是否发生完成****************************/
    	if( state->network_run_state.send_st == SEND_OK )
    	{
            state->network_run_state.send_st = 0;
    		ret = pdPASS;
    	}
    } 
	return ret;
}

/** ****************************************************************************
* @remarks       static uint32_t national808_create_network_state_cb( uint8_t n , uint8_t *arg )
* @brief         NET网络状态回调函数
* @param[in]     *pv 不定类型的函数入参 
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void national808_create_network_state_cb( void *pv)
{
	socket_net_state_s *net_state = NULL;
    socket_state_t *state = NULL;
	if( pv == NULL )				/*空指针返回*/
	{
		return;
	}
	net_state = ( socket_net_state_s * )pv;
    state = &socket_state_1;
    //gaoz_log_debug_printf(DEBUG_MODE,"800b","Network status:%d,%d\r\n", net_state->index_id ,net_state->net_state);
	switch( net_state->net_state )
	{
	    case SOCKET_STATE_INIT:
            /*无*/
            break;
		case SOCKET_SEND_OK:		/*数据发送成功*/
			state->network_run_state.send_st = SEND_OK;
			national808_socket_semaphore_put(); /*发送信号量*/
			break;
		case SOCKET_SEND_ERROR:		/*数据发送失败*/
			state->network_run_state.send_st = SEND_ERR;
			national808_socket_semaphore_put(); /*发送信号量*/
			break;
		case SOCKET_RECV_OK:		/*数据接收成功*/
			state->network_run_state.recv_st = RECV_OK;
			break;
		case SOCKET_RECV_ERROR:		/*数据接收失败*/
			state->network_run_state.recv_st = RECV_ERR;
			break;
		case SOCKET_LINK_ERROR:		/*网络连接失败*/
			state->network_run_state.link_st = LINK_ERR;
			break;
		case SOCKET_CSQ_ERROR:		/*网络信息状态异常*/
			state->network_run_state.csq_st = CSQ_ERR;
			break;
		case SOCKET_REG_ERROR:		/*网络附着网络失败*/
			state->network_run_state.reg_st = REG_ERR;
			break;
		case GSM_NET_SLEEP:			/*底层网络睡眠*/
			state->network_run_state.net_st = NET_SLEEP;
			break;
		case GSM_NET_STOP:			/*底层网络停止*/
			state->network_run_state.net_st = NET_STOP;
			break;
		case GSM_NET_RST:			/*底层网络需要复位*/
			state->network_run_state.net_st = NET_RST;
			break;
		case GSM_NET_RUN:			/* 底层网络运行中*/
			state->network_run_state.net_st = NET_RUN;
			break;
	}
}

/** ****************************************************************************
* @remarks       static uint32_t national808_net_switch_st_check(mangpatio_info_t  *_info)
* @brief         判断参数表模式字段是否满足联网要求
* @param[in]    
* @param[in]     major_info应用表
* @param[out]    无
* @return        pdFAIL 网络关  pdPASS 网络开
* @attention     
*******************************************************************************/
static uint32_t national808_net_switch_st_check(terminal_info_t	*major_info)
{
	uint32_t ret = pdFAIL;
	if( (major_info == NULL) )
	{
		return ( ret );
	}
	if( (major_info->Mode == 0x20) || (major_info->Mode == 0x10) )
	{
		ret = pdPASS;
	}
	else if( major_info->Mode == 0x02 )
	{
		ret = pdPASS;
	}
	else 
	{
		ret = pdFAIL;
	}
	return ret;
}


/** ****************************************************************************
* @remarks       static uint32_t national808_net_ip_addr_check( char *ip )
* @brief         检测网络连接的IP地址，与固定域名是否为相同的IP地址
* @param[in]     *ip IP地址源地址
* @param[in]     无
* @param[out]    无
* @return        pdFAIL - 失败  pdPASS - 成功
* @attention     
*******************************************************************************/
static uint32_t national808_net_ip_addr_check( char *ip )
{
	uint32_t ret = pdFAIL;
	char reg_ip[64] = { 0 }; /*注册IP地址*/
	char sta_ip[64] = { 0 }; /*固定IP地址*/
	uint8_t wait = 0;

	for( wait = 0; wait < 3; wait ++ )
	{
		/*判断注册IP地址类型，是否为域名方式。如果为域名需要进行域名->IP转换*/
		if( gaoz_connect_type_check( (uint8_t *)ip ) == CONNECT_TYPE_DOMAIN )
		{
			if( gaoz_socket_dns_ip_addr_get( ip,reg_ip ) == pdPASS )
			{
				ret = pdPASS;
			}
		}
		else
		{
			memcpy( ( char *)reg_ip, (const char *)ip, strlen((const char *)ip) );
			ret = pdPASS;
		}
		/*获取固定域名IP地址*/
		if( ret == pdPASS )
		{
			if( gaoz_socket_dns_ip_addr_get( "800b.zykuaiche.com",sta_ip ) == pdPASS )
			{
				log_debug_printf(INFOR_MODE,"800b" ,"Registered IP address:%s,Static IP address:%s\r\n",reg_ip,sta_ip);
				if( strlen((const char *)reg_ip) == strlen((const char *)sta_ip) )
				{
					if( memcmp( reg_ip, sta_ip, strlen((const char *)reg_ip) ) == 0 )	/*判断的IP地址相同*/
					{
						national_808_ip_addr_t = INTERNAL_IP_ADDR;
					}
					else
					{
						national_808_ip_addr_t = EXTERNAL_IP_ADDR;
					}
				}
				else
				{
					national_808_ip_addr_t = EXTERNAL_IP_ADDR;
				}
				ret = pdPASS;
			}
			else
			{
				ret = pdFAIL;
			}
		}
		/*当判断成功时直接退出for循环，否则延迟1S钟重新进行获取*/
		if( ret == pdPASS )
		{
			break;
		}
		else
		{
			gaoz_task_sleep( 1000 );
		}
	}
	return ret;
}

/** ****************************************************************************
* @remarks       static uint32_t national_net_create_st_check(socket_handle_s * handle , socket_state_t * state)
* @brief         创建 SOCKET 连接检测状态
* @param[in]     *handle 网络设备节点
* @param[in]     *state 网络状态
* @param[out]    无
* @return        pdFAIL 网络异常 pdFAIL 网络正常
* @attention     进入网络连接成功后分别对网络状态进行检测，其中1 2 3 4 5
			    代表检测的先后次序，同时也代表了事件检测的有限等级。
			    1、网络发送接收数据状态判断，超出设定次数后进行网络关闭；
			    2、网络链接异常，底层驱动设置。网络失效断开链接
			    3、网络信号状态异常，底层驱动设置。等待网络信号恢复正常但是不关闭网络链接。(链接超时后底层驱动会通知 2 )
			    4、网络附着状态异常，底层驱动设置。网络失效断开链接
			    5、底层网络运行状态设置，底层驱动设置。网络失效断开链接
*******************************************************************************/
static uint32_t national808_net_create_st_check(socket_handle_s *handle , socket_state_t *state, char *ip, uint16_t port)
{
	uint32_t ret = pdFAIL;
	static uint32_t reset_net_time = 0;
	if(( handle == NULL ) || ( state == NULL ))
	{
		return ( ret );
	}

	
	
	if( state->create_socket_state  == SOCKET_LINK_CREATE_ERROR )
	{	
		memset((uint8_t *)state , 0x00 , sizeof(socket_state_t) );
		n808_authsta_set(N808_AUTH_FAIL);
		if(national808_net_switch_st_check(&taginf) == pdPASS)
		{
			gaoz_power_man_wakeup_task_num_run(); /*wake up*/ 
			gaoz_socket_bind( (socket_handle_s*)handle, ip, port, e_socket_protocol_tcp, national808_create_network_state_cb );
			ret = gaoz_socket_connect( (socket_handle_s*)handle );
			if( ret == pdPASS )
			{
				national808_net_ip_addr_check( ip );	/*判断注册IP地址与固定IP地址是否相同*/
				log_debug_printf(INFOR_MODE,"800b" ,"ip debug n808_app ip:%s,port:%d\r\n",ip,port);
				//log_debug_send(INFOR_MODE,"808_" ,"Registered platform network is successful\r\n",0);
				national808_net_runing_state_set( TER_RUNING_REG );
				state->create_socket_state = SOCKET_LINK_CREATE_OK;
				//national808_data_st.send_st = N808_SEND_INIT;
				national808_send_state = N808_SEND_INIT;
				national808_ctrllock_state_set( CTLOCK_OK );
				gaoz_task_sleep( 1000 );	/*系统延迟1S钟等待网络稳定后，开始发送数据*/
				reset_net_time = 0;
			}
			gaoz_power_man_wakeup_task_num_stop();
		}
		else
		{
			ret = pdFAIL;
		}
	}
	else if( state->create_socket_state == SOCKET_LINK_CREATE_OK)
	{
        /*判断数据收发状态是否等待状态异常*/
/*1*/   if(( national808_net_data.send_st >= NET_DATA_SEND_RECV_COUNTER ) || ( national808_net_data.recv_st >= NET_DATA_SEND_RECV_COUNTER ))
        { 
			log_debug_printf(INFOR_MODE,"800b" ,"socket_close %d,%d\r\n",national808_net_data.send_st,national808_net_data.recv_st);
            socket_close((socket_handle_s*)handle);
            state->create_socket_state = SOCKET_LINK_CREATE_ERROR;
			state->network_run_state.link_st = 0x00;
            ret = pdFAIL;

			if( national808_net_data.send_st >= NET_DATA_SEND_RECV_COUNTER )
			{
				national808_auth_reason_set(NET_AUTH_REASON_SEND_ERR);
			}
			else 
			{
				national808_auth_reason_set(NET_AUTH_REASON_RECV_ERR);
			}
 
            national808_net_data.send_st = 0;
            national808_net_data.recv_st = 0;
        }
        /*判断网络模块网络连接状态异常*/
/*2*/	else if( state->network_run_state.link_st == LINK_ERR )
		{
			log_debug_printf(INFOR_MODE,"800b" ,"socket_close link_st%d\r\n",state->network_run_state.link_st);
			gaoz_socket_close((socket_handle_s*)handle);
			state->create_socket_state = SOCKET_LINK_CREATE_ERROR;
			state->network_run_state.link_st = 0x00;
			ret = pdFAIL;

			national808_auth_reason_set(NET_AUTH_REASON_LINK_ERR);
		}
		/*信号质量异常网络注册网络节点不关闭等待网络信号回复正常*/
/*3*/	else if( state->network_run_state.csq_st == CSQ_ERR )
		{
			log_debug_printf(INFOR_MODE,"800b" ,"debug 800b socket_close csq_st%d\r\n",state->network_run_state.csq_st);
			
			state->network_run_state.csq_st = 0x00;
			ret = pdFAIL;

			national808_auth_reason_set(NET_AUTH_REASON_CSQ_ERR);
		}
		/*判断GSM模块网络注册状态异常*/
/*4*/	else if( state->network_run_state.reg_st == REG_ERR )
		{
			log_debug_printf(INFOR_MODE,"800b" ,"socket_close reg_st%d\r\n",state->network_run_state.reg_st);
			gaoz_socket_close((socket_handle_s*)handle);
			state->create_socket_state = SOCKET_LINK_CREATE_ERROR;
			state->network_run_state.reg_st = 0x00;
			ret = pdFAIL;

			national808_auth_reason_set(NET_AUTH_REASON_REG_ERR);
		}
		/*网络进入 (睡眠 / 停止 / 复位 / 运行) 的状态*/
/*5*/	else if( state->network_run_state.net_st != 0 )
		{
			if((state->network_run_state.net_st == NET_SLEEP)||(state->network_run_state.net_st == NET_STOP))
			{
				// log_debug_printf(INFOR_MODE,"800b" ,"debug 800b state->network_run_state.net_st[NET_SLEEP]%d taginf.heartBeatDly:%d\r\n",state->network_run_state.net_st,hex4CombineOne(taginf.heartBeatDly));
			
				state->network_run_state.net_st = 0;
				if(hex4CombineOne(taginf.heartBeatDly) != 0)
				{
					gaoz_system_wakeup_rtc_time_set(RTC_NET,hex4CombineOne(taginf.heartBeatDly));
				}
				/*网络进入休眠时不需要通知应用程序，屏蔽掉网络休眠标志位。YXX 2022.07.25*/
				//gaoz_log_debug_printf(INFOR_MODE,"800b","sleep gaoz_system_wakeup_rtc_time_set : %d\r\n",hex4CombineOne(taginf.heartBeatDly));	
				//if(n808_netready != NET_READY_FAIL)
				//{
				//	n808_netready = NET_READY_FAIL;
				//}
				ret = pdFAIL;
			}
			else if(state->network_run_state.net_st == NET_RUN)
			{	
				// log_debug_printf(INFOR_MODE,"800b" ,"debug 800b state->network_run_state.net_st[NET_RUN]%d\r\n",state->network_run_state.net_st);
				// log_debug_printf(INFOR_MODE,"800b" ,"debug 800b gaoz_sys_work_mode_get[%d],national808_net_runing_state_get[%d]\r\n",gaoz_sys_work_mode_get(),national808_net_runing_state_get());
				 
				state->network_run_state.net_st = 0;
				/*网络进入休眠时不需要通知应用程序，屏蔽掉网络休眠标志位。YXX 2022.07.25*/
				//if(n808_netready != NET_READY_OK)
				//{
				//	n808_netready = NET_READY_OK;
				//}
				ret = pdPASS;
			} 
		}
		// else if(( reset_net_time ++ ) > 5 )
		// {
		// 	reset_net_time = 0;
		// 	log_debug_printf(INFOR_MODE,"800b" ,"reset_net_time = %d\r\n",reset_net_time);
		// 	gaoz_socket_close((socket_handle_s*)handle);
		// 	state->create_socket_state = SOCKET_LINK_CREATE_ERROR;
		// 	ret = pdFAIL;
		// }
/*6*/	else
		{ 
			ret = pdPASS;
		}
	}
	else
	{
		ret = pdFAIL;
	}
	return ( ret );
}
/** ****************************************************************************
* @remarks       national_run_state_e national_net_runing_state_get( void )
* @brief         获取国标平台运行状态
* @param[in]     无
* @param[out]    无
* @return        运行状态
* @attention     在系统启动后进行创建
*******************************************************************************/
national_run_state_e national808_net_runing_state_get( void )
{
	return national808_runing_st;
}

/** ****************************************************************************
* @remarks       void national_net_runing_state_set( national_run_state_e  state )
* @brief         设置国标平台运行状态
* @param[in]     state 运行状态
* @param[out]    无
* @return        无
* @attention     在系统启动后进行创建
*******************************************************************************/
void national808_net_runing_state_set( national_run_state_e  state )
{
	national808_runing_st = state;
}
/** ****************************************************************************
* @remarks       national808_ctrllock_e national808_ctrllock_state_get( void )
* @brief         控锁状态
* @param[in]     无
* @param[out]    无
* @return        运行状态
* @attention     在系统启动后进行创建
*******************************************************************************/
national808_ctrllock_e national808_ctrllock_state_get( void )
{
	return national808_ctlock;
}

/** ****************************************************************************
* @remarks       void national808_ctrllock_state_set( national808_ctrllock_e  state )
* @brief         设置控锁状态
* @param[in]     state 运行状态
* @param[out]    无
* @return        无
* @attention     在系统启动后进行创建
*******************************************************************************/
void national808_ctrllock_state_set( national808_ctrllock_e  state )
{
	national808_ctlock = state;
}
/** ****************************************************************************
* @remarks       static void national808_net_patiores_queue_create( void )
* @brief         国标数据平台接收命令应答消息队列创建
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void national808_net_patiores_queue_create( void )
{
    national808_send_patiores_queue = gaoz_queue_create( NET_ACK_QUEUE_MAX_NUM, sizeof( national_net_res_msg_t ) );
    if( national808_send_patiores_queue == 0 )
    {
        while( 1 );
    }
}
/** ****************************************************************************
* @remarks       static void national808_net_devres_queue_create( void )
* @brief         国标数据平台接收数据应答消息队列创建
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void national808_net_devres_queue_create( void )
{
	national808_send_devres_queue = gaoz_queue_create( NET_ACK_QUEUE_MAX_NUM, sizeof( national808_net_devres_msg_t ) );
    if( national808_send_devres_queue == 0 )
    {
        while( 1 );
    }
}

/** ****************************************************************************
* @remarks       void national808_ctlock_queue_create( void )
* @brief         控锁消息队列创建
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void national808_ctlock_queue_create( void )
{
	national808_ctlock_queue = gaoz_queue_create( NET_ACK_QUEUE_MAX_NUM, sizeof( national808_ctrllock_msg_t ) );
    if( national808_ctlock_queue == 0 )
    {
        while( 1 );
    }
}
/** ****************************************************************************
* @remarks       void national808_ctlock_res_queue_create( void )
* @brief         控锁异步消息队列创建
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void national808_ctlock_res_queue_create( void )
{
	national808_ctlock_res_queue = gaoz_queue_create( NET_ACK_QUEUE_MAX_NUM, sizeof( national808_ctrllock_msg_t ) );
    if( national808_ctlock_res_queue == 0 )
    {
        while( 1 );
    }
}
/** ****************************************************************************
* @remarks       void national808_upgrade_queue_create( void )
* @brief         升級消息队列创建
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void national808_upgrade_queue_create( void )
{
	national808_upgrade_queue = gaoz_queue_create( NET_ACK_QUEUE_MAX_NUM, sizeof( update_result_t ) );
    if( national808_upgrade_queue == 0 )
    {
        while( 1 );
    }
}
/** ****************************************************************************
* @remarks       static uint32_t national808_net_patiores_queue_get( national_net_res_msg_t *res_msg , uint32_t delay_time )
* @brief         获取国标平台网络命令应答消息队列
* @param[in]     *res_msg 获取的数据地址
* @param[in]     delay_time 等待的时间
* @param[out]    无
* @return        pdPASS 接收数据成功 ，pdFAIL 接收数据失败
* @attention     无
*******************************************************************************/
static uint32_t national808_net_patiores_queue_get( national_net_res_msg_t *res_msg , uint32_t delay_time )
{
    if( national808_send_patiores_queue == 0 )
    {
        national808_net_patiores_queue_create();
    }
    if(gaoz_queue_get( national808_send_patiores_queue, res_msg, delay_time )  >= 0 ) //
    {
        return pdPASS;
    }
  
    return pdFAIL;
}

/** ****************************************************************************
* @remarks       static uint8_t national808_net_patiores_queue_put( national_net_res_msg_t *res_msg )
* @brief         发送国标网络平台应答数据
* @param[in]     *res_msg 发送的数据地址
* @param[out]    无
* @return        1 发送数据成功 ，0 发送数据失败
* @attention     无
*******************************************************************************/
static uint8_t national808_net_patiores_queue_put( national_net_res_msg_t *res_msg )
{
    if( gaoz_queue_put( national808_send_patiores_queue, res_msg, 1000 ) == 0 )
    {
        return 1;
    }
	else
	{
		return 0;
	}
}
/** ****************************************************************************
* @remarks       static uint32_t national808_net_devres_queue_get( national_net_res_msg_t *res_msg , uint32_t delay_time )
* @brief         获取国标平台网络数据应答消息队列
* @param[in]     *res_msg 获取的数据地址
* @param[in]     delay_time 等待的时间
* @param[out]    无
* @return        pdPASS 接收数据成功 ，pdFAIL 接收数据失败
* @attention     无
*******************************************************************************/
static uint32_t national808_net_devres_queue_get( national808_net_devres_msg_t *res_msg , uint32_t delay_time )
{
    if( national808_send_devres_queue == 0 )
    {
        national808_net_devres_queue_create();
    }
    if(gaoz_queue_get( national808_send_devres_queue, res_msg, delay_time )  == 0 ) //等待回应信号量
    {
        return pdPASS;
    }
    else
    {
        return pdFAIL;
    }
    return pdFAIL;
}

/** ****************************************************************************
* @remarks       static uint8_t national808_net_devres_queue_put( national_net_res_msg_t *res_msg )
* @brief         发送国标网络数据应答数据
* @param[in]     *res_msg 发送的数据地址
* @param[out]    无
* @return        1 发送数据成功 ，0 发送数据失败
* @attention     无
*******************************************************************************/
uint8_t national808_net_devres_queue_put( national808_net_devres_msg_t *res_msg )
{
    if( gaoz_queue_put( national808_send_devres_queue, ( void * )res_msg, 1000 ) == 0 )
    {
        return 1;
    }
	else
	{
		return 0;
	}
}
/** ****************************************************************************
* @remarks       uint32_t national808_ctlock_queue_get( national808_ctrllock_msg_t *res_msg , uint32_t delay_time )
* @brief         获取控锁消息队列
* @param[in]     *res_msg 获取的数据地址
* @param[in]     delay_time 等待的时间
* @param[out]    无
* @return        pdPASS 接收数据成功 ，pdFAIL 接收数据失败
* @attention     无
*******************************************************************************/
uint32_t national808_ctlock_queue_get( national808_ctrllock_msg_t *res_msg , uint32_t delay_time )
{
    if( national808_ctlock_queue == 0 )
    {
        national808_ctlock_queue_create();
    }
    if(gaoz_queue_get( national808_ctlock_queue, res_msg, delay_time )  == 0 ) //等待回应信号量
    {
        return pdPASS;
    }
    else
    {
        return pdFAIL;
    }
    return pdFAIL;
}


/** ****************************************************************************
* @remarks       void gaoz_queue_clear(uint32_t id) 
* @brief         清空消息队列
* @param[in]     id 队列ID；
* @param[out]    无
* @return        
* @attention     无
*******************************************************************************/
void gaoz_queue_clear(uint32_t id) 
{
	fibo_queue_reset(id);
}

/** ****************************************************************************
* @remarks       uint8_t national808_ctlock_queue_put( national_net_res_msg_t *res_msg )
* @brief         发送控锁消息
* @param[in]     *res_msg 发送的数据地址
* @param[out]    无
* @return        1 发送数据成功 ，0 发送数据失败
* @attention     无
*******************************************************************************/
uint8_t national808_ctlock_queue_put( national808_ctrllock_msg_t *res_msg )
{
	gaoz_queue_clear(national808_ctlock_queue);

    if( gaoz_queue_put( national808_ctlock_queue, ( void * )res_msg, 1000 ) == 0 )
    {
        return 1;
    }
	else
	{
		return 0;
	}
}
/** ****************************************************************************
* @remarks       uint32_t national808_ctlock_res_queue_get( national808_ctrllock_msg_t *res_msg , uint32_t delay_time )
* @brief         获取控锁响应消息队列
* @param[in]     *res_msg 获取的数据地址
* @param[in]     delay_time 等待的时间
* @param[out]    无
* @return        pdPASS 接收数据成功 ，pdFAIL 接收数据失败
* @attention     无
*******************************************************************************/
static uint32_t national808_ctlock_res_queue_get( national808_ctrllock_msg_t *res_msg , uint32_t delay_time )
{
    if( national808_ctlock_res_queue == 0 )
    {
        national808_ctlock_res_queue_create();
    }
    if(gaoz_queue_get( national808_ctlock_res_queue, res_msg, delay_time )  == 0 ) //等待回应信号量
    {
        return pdPASS;
    }
    else
    {
        return pdFAIL;
    }
    return pdFAIL;
}

/** ****************************************************************************
* @remarks       uint8_t national808_ctlock_res_queue_put( national_net_res_msg_t *res_msg )
* @brief         发送控锁响应消息
* @param[in]     *res_msg 发送的数据地址
* @param[out]    无
* @return        1 发送数据成功 ，0 发送数据失败
* @attention     无
*******************************************************************************/
uint8_t national808_ctlock_res_queue_put( national808_ctrllock_msg_t *res_msg )
{
    if( gaoz_queue_put( national808_ctlock_res_queue, ( void * )res_msg, 1000 ) == 0 )
    {
        return 1;
    }
	else
	{
		return 0;
	}
}
/** ****************************************************************************
* @remarks       uint32_t national808_upgrade_queue_get( update_result_t *res_msg , uint32_t delay_time )
* @brief         获取升级消息队列
* @param[in]     *res_msg 获取的数据地址
* @param[in]     delay_time 等待的时间
* @param[out]    无
* @return        pdPASS 接收数据成功 ，pdFAIL 接收数据失败
* @attention     无
*******************************************************************************/
static uint32_t national808_upgrade_queue_get( update_result_t *res_msg , uint32_t delay_time )
{
    if( national808_upgrade_queue == 0 )
    {
        national808_ctlock_res_queue_create();
    }
    if(gaoz_queue_get( national808_upgrade_queue, res_msg, delay_time )  == 0 ) //等待回应信号量
    {
        return pdPASS;
    }

    return pdFAIL;
}

/** ****************************************************************************
* @remarks       uint8_t national808_upgrade_queue_put( national_net_res_msg_t *res_msg )
* @brief         发送升级消息
* @param[in]     *res_msg 发送的数据地址
* @param[out]    无
* @return        1 发送数据成功 ，0 发送数据失败
* @attention     无
*******************************************************************************/
uint8_t national808_upgrade_queue_put( update_result_t *res_msg )
{
    if( gaoz_queue_put( national808_upgrade_queue, ( void * )res_msg, 1000 ) == 0 )
    {
        return 1;
    }
	else
	{
		return 0;
	}
}
/** ****************************************************************************
* @remarks       uint32_t national_data_manage_fun( national_send_data_e *send_st , national_response_e *recv_st)
* @brief         国标数据管理功能
* @param[in]     无
* @param[out]    *send_st 发送状态，×recv_st 接收状态
* @return        pdPASS 数据发送失败 pdFAIL 数据发送成功
* @attention     
*******************************************************************************/
static uint32_t national808_data_manage_fun( national_send_data_e *send_st , national_response_e *recv_st)
{
    uint32_t ret = pdFAIL, data_len = 0;
	uint8_t txbuf[1024]={0}, ctrl_st = 0;
    uint16_t txbuflen=0;
    national_run_state_e run_st;
	national808_net_devres_msg_t devres_msg;
	national808_ctrllock_msg_t ctlock_msg;
	update_result_t upgrade_msg;
	system_work_mode_s sys_st;

    sys_st = gaoz_sys_work_mode_get();
	run_st = national808_net_runing_state_get();
    *send_st = PLAT_SEND_INIT;
    *recv_st = PLAT_RESPONSE_INIT;
	/*检测网络运行状态，检测到处于数据状态时获取控制命令*/
	if( run_st == TER_RUNING_DATA )
	{
		if( national808_net_ctrl_infor_get( (uint8_t *)&ctrl_st ) == pdPASS )
		{
			run_st = ( national_run_state_e )ctrl_st;
		}
	}
	switch( run_st )
	{
		/*判断终端运行在初始化状态进行终端登陆平台*/
		case TER_RUNING_REG: 
		#if( USER_AES_ENCRYPT_N800 == 1 )
			memset(txbuf,0,sizeof(txbuf));
			txbuflen = SendRegister(txbuf);
			//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
			if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
			{
				if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
				{
					*send_st = PLAT_SEND_OK;
					*recv_st = PLAT_HAVE_RESPONSE;
					gaoz_log_debug_printf(INFOR_MODE,"800b","SendRegister:[0100] Send OK\r\n");	
				}
				else /*数据发送失败，无需进行应答*/
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","SendRegister:[0100] Send ERROR\r\n");	
				}
			}
			else
			{
				*send_st = PLAT_SEND_ERR;
				gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
			}
			ret = pdPASS;
		#else
		    if(taginf.AuthCodeFlag != 161)
			{
				memset(txbuf,0,sizeof(txbuf));
				txbuflen = SendRegister(txbuf);
				//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
				if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
				{
					if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
					{
						*send_st = PLAT_SEND_OK;
						*recv_st = PLAT_HAVE_RESPONSE;
						gaoz_log_debug_printf(INFOR_MODE,"800b","SendRegister:[0100] Send OK\r\n");	
					}
					else /*数据发送失败，无需进行应答*/
					{
						*send_st = PLAT_SEND_ERR;
						gaoz_log_debug_printf(INFOR_MODE,"800b","SendRegister:[0100] Send ERROR\r\n");	
					}
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
				}
				ret = pdPASS;
            }
			else
			{
				national808_net_runing_state_set( TER_RUNING_AUTH ); 	
			}
		#endif
		break;
		case TER_RUNING_AUTH:
			//national808_set_time_tick = gaoz_get_systick(); /*获取当前最新的系统时钟*/
			national808_herat_time_tick = gaoz_get_systick();
			national808_bms_time_tick = gaoz_get_systick();
			if((taginf.AuthCodeFlag == 161))
            {
				memset(txbuf,0,sizeof(txbuf));
				txbuflen = Authentication(txbuf);
				//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
				if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
				{
					if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
					{   
						*send_st = PLAT_SEND_OK;
						*recv_st = PLAT_HAVE_RESPONSE;
						gaoz_log_debug_printf(INFOR_MODE,"800b","n808_app Authentication:[0501] Send OK\r\n");		
					}
					else/*数据发送失败，无需进行应答*/
					{
						*send_st = PLAT_SEND_ERR;
						gaoz_log_debug_printf(INFOR_MODE,"800b","Authentication:[0501] Send ERROR\r\n");
					}
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
				}
				ret = pdPASS;
			}
			else
			{
				national808_net_runing_state_set( TER_RUNING_REG );
			}
		break;
		/*发送数据包*/
		case TER_RUNING_DATA:
		{
			if( sys_st == SYS_ST_RUN )
			{
				if( pdPASS == sys_timestamp_delay(( uint32_t * )&national808_herat_time_tick, hex4CombineOne(taginf.heartBeatDly) * GAOZ_TICK_PERIOD_S ) )
				{
					memset(txbuf,0,sizeof(txbuf));
					txbuflen = SendHeart(txbuf);
					//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
					if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
					{
						if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
						{
							*send_st = PLAT_SEND_OK;
							*recv_st = PLAT_HAVE_RESPONSE;	
							gaoz_log_debug_printf(INFOR_MODE,"800b","SendHeart:[0506] Send OK\r\n");
						}
						else
						{
							*send_st = PLAT_SEND_ERR;
							gaoz_log_debug_printf(INFOR_MODE,"800b","SendHeart:[0506] Send ERROR\r\n");
						}
					}
					else
					{
						*send_st = PLAT_SEND_ERR;
						gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
					}
					ret = pdPASS;
				}
				// else if( pdPASS == sys_timestamp_delay(( uint32_t * )&national808_bms_time_tick, 4 * GAOZ_TICK_PERIOD_S ) )
				else if(warmcar_bms_semaphore_get(10))
				{
					memset(txbuf,0,sizeof(txbuf));
					txbuflen = network_data_bms_infor_transmission(txbuf);
					if( txbuflen != 0 )
					{
						//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
						if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
						{
							if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
							{
								*send_st = PLAT_SEND_OK;
								*recv_st = PLAT_HAVE_RESPONSE;	
								gaoz_log_debug_printf(INFOR_MODE,"800b","SendBmsData:[0630] Send OK\r\n");
							}
							else
							{
								*send_st = PLAT_SEND_ERR;
								gaoz_log_debug_printf(INFOR_MODE,"800b","SendBmsData:[0630] Send ERROR\r\n");
							}
						}
						ret = pdPASS;
					}
				}
				else
				{
					/*读取FLASH中的数据*/ 
					#if (OS_HISTORY_VEHICLE_INFO_REPORT == 1)
					if( (national808_send_state == N808_SEND_INIT) || (national808_send_state == N808_SENDRSP_OK) )
					{
						memset(txbuf,0,sizeof(txbuf));
						txbuflen = 0;
						data_len = gaoz_save_data_read( sfb_handle_id , txbuf , &txbuflen );
						if( ( data_len != 0 ) && ( data_len < 0xFFFFFFFF ) )
						{ 
							memset(national808_data_st.send_data,0,UNIT_FLASH_DATA_LEN);
							national808_data_st.send_datalen = 0;
							if( txbuflen <= UNIT_FLASH_DATA_LEN )
							{	
								memcpy(national808_data_st.send_data,txbuf , txbuflen );
								national808_data_st.send_datalen = txbuflen;
								national808_send_state = N808_SEND_WAIT;
							}
							gaoz_log_debug_printf(INFOR_MODE,"800b","gaoz_save_data_read ret: %ld,txbuflen:%d\r\n",data_len,txbuflen);
						}
						else
						{
							//gaoz_log_debug_printf(INFOR_MODE,"800b","gaoz_save_data_read ret:%ld\r\n",data_len);
							if( data_len == 0xFFFFFFFF )
							{
								if(n808_cle_save_data() != pdPASS)
								{
									gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]n808_cle_save_data fail\r\n",__FUNCTION__, __LINE__);
								}
							}
						}
					}
					#endif

					/*当数据读取成功时，进行网络发送*/
					if(( national808_send_state == N808_SEND_WAIT ) || ( national808_send_state == N808_SEND_OK ))
					{
						//ret = gaoz_socket_write( &socket_handle_1 , national808_data_st.send_data , national808_data_st.send_datalen );
						if( gaoz_socket_write( &socket_handle_1 , national808_data_st.send_data , national808_data_st.send_datalen ) == pdPASS )
						{
							if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
							{	
								*send_st = PLAT_SEND_OK;
								*recv_st = PLAT_HAVE_RESPONSE;	
								national808_send_state = N808_SEND_OK;
								gaoz_log_debug_printf(INFOR_MODE,"800b","positioninfo:[0504] Send OK\r\n");	
							}
							else
							{		
								*send_st = PLAT_SEND_ERR;
								gaoz_log_debug_printf(INFOR_MODE,"800b","positioninfo:[0504] Send ERROR\r\n");
							}
							national808_herat_time_tick = gaoz_get_systick();	
						}
						else
						{
							*send_st = PLAT_SEND_ERR;
							gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
						}
						ret = pdPASS;
					}
					/* 異步應答 */
					if( national808_ctlock_res_queue_get( &ctlock_msg , 100 ) == pdPASS )
					{	  
						memset(txbuf,0,sizeof(txbuf));
						gaoz_log_debug_printf(INFOR_MODE,"800b","ctlock_msg.lock_err:%d,ctlock_msg.lock_res.respondsta:%d,ctlock_msg.lock_type:%d\r\n",ctlock_msg.lock_err,ctlock_msg.lock_res.respondsta,ctlock_msg.lock_type);
						txbuflen = lockrespond(txbuf,&ctlock_msg);
						log_debug_send(INFOR_MODE , NET_MAN_NAME ,"hello lockrespond ok" ,0 );
						//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
						if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
						{
							if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
							{ 
								*send_st = PLAT_SEND_OK;
								*recv_st = PLAT_NO_RESPONSE;	
								gaoz_log_debug_printf(INFOR_MODE,"800b","lockrespond Send OK:%x\r\n",ctlock_msg.lock_res.respondcmd);	
							}
							else
							{
								*send_st = PLAT_SEND_ERR;
								gaoz_log_debug_printf(INFOR_MODE,"800b","lockrespond Send ERROR:%x\r\n",ctlock_msg.lock_res.respondcmd);	
							}
							national808_herat_time_tick = gaoz_get_systick();	
						}
						else
						{
							*send_st = PLAT_SEND_ERR;
							gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
						}
						log_debug_send(INFOR_MODE , NET_MAN_NAME ,"hello national808_socket_send ctlock" ,0 );
						ret = pdPASS;
						national808_ctrllock_state_set(CTLOCK_OK);
					}
					/* upgrade */
					if( national808_upgrade_queue_get( &upgrade_msg, 100 ) == pdPASS)
					{
						memset(txbuf,0,sizeof(txbuf));
						txbuflen = updateresult(&upgrade_msg,txbuf);
						//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
						if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
						{
							if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
							{   
								*send_st = PLAT_SEND_OK;
								*recv_st = PLAT_NO_RESPONSE;	
								gaoz_log_debug_printf(INFOR_MODE,"800b","Upgrade:[0108] Send OK\r\n");	
							}
							else
							{
								*send_st = PLAT_SEND_ERR;
								gaoz_log_debug_printf(INFOR_MODE,"800b","Upgrade:[0108] Send ERROR\r\n");	
							}
							national808_herat_time_tick = gaoz_get_systick();	
						}
						else
						{
							*send_st = PLAT_SEND_ERR;
							gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
						}
						if(upgrade_msg.update_types != 0)
						{ 
							national808_net_runing_state_set(TER_RUNING_AUTH);
						}
						ret = pdPASS;
					}
				}
			}
			else if(sys_st == SYS_ST_WAKE)
			{ 		
				 /* 異步應答 */
				if( national808_ctlock_res_queue_get( &ctlock_msg , 100 ) == pdPASS )
				{
					 memset(txbuf,0,sizeof(txbuf));
					 gaoz_log_debug_printf(INFOR_MODE,"800b","ctlock_msg.lock_err:%d,ctlock_msg.lock_res.respondsta:%d,ctlock_msg.lock_type:%d\r\n",ctlock_msg.lock_err,ctlock_msg.lock_res.respondsta,ctlock_msg.lock_type);
					 txbuflen = lockrespond(txbuf,&ctlock_msg);
					 //ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
					 if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
					 {
						 if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
						 {   
							 *send_st = PLAT_SEND_OK;
							 *recv_st = PLAT_NO_RESPONSE;	
							 wakeup_source_set( POWER_INIT );
							 gaoz_log_debug_printf(INFOR_MODE,"800b","lockrespond Send OK:%x\r\n",ctlock_msg.lock_res.respondcmd);	
						 }
						 else
						 {
							 *send_st = PLAT_SEND_ERR;
							 gaoz_log_debug_printf(INFOR_MODE,"800b","lockrespond Send ERROR:%x\r\n",ctlock_msg.lock_res.respondcmd);	
						 }
					 }
					 else
					 {
						 *send_st = PLAT_SEND_ERR;
						 gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
					 }
					 national808_ctrllock_state_set( CTLOCK_OK);
				}
				
				if( wakeup_source_get() != POWER_INIT )
				{
					// gaoz_log_debug_printf(INFOR_MODE,"800E","800e wakeup_source_get:%d\r\n",wakeup_source_get());	
					gaoz_power_man_wakeup_task_num_run();
					
					/* upgrade */
					if( national808_upgrade_queue_get( &upgrade_msg, 100 ) == pdPASS)
					{
						memset(txbuf,0,sizeof(txbuf));
						txbuflen = updateresult(&upgrade_msg,txbuf);
						//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
						if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
						{
							if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
							{
								*send_st = PLAT_SEND_OK;
								*recv_st = PLAT_NO_RESPONSE;
								wakeup_source_set( POWER_INIT );
								gaoz_log_debug_printf(INFOR_MODE,"800b","sleep upgrade:[0108] Send OK\r\n");	
							}
							else
							{
								*send_st = PLAT_SEND_ERR;
								gaoz_log_debug_printf(INFOR_MODE,"800b","sleep upgrade:[0108] Send ERROR\r\n");	
							}
						}
						else
						{
							*send_st = PLAT_SEND_ERR;
							gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
						}
						if(upgrade_msg.update_types != 0)
						{ 	
							national808_net_runing_state_set(TER_RUNING_AUTH);
						}
						ret = pdPASS;
					}

					if(warmcar_bms_semaphore_get(10))
					{
						memset(txbuf,0,sizeof(txbuf));
						txbuflen = network_data_bms_infor_transmission(txbuf);
						if( txbuflen != 0 )
						{
							//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
							if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
							{
								if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
								{
									*send_st = PLAT_SEND_OK;
									*recv_st = PLAT_HAVE_RESPONSE;	
									gaoz_log_debug_printf(INFOR_MODE,"800b","SendBmsData:[0630] Send OK\r\n");
								}
								else
								{
									*send_st = PLAT_SEND_ERR;
									gaoz_log_debug_printf(INFOR_MODE,"800b","SendBmsData:[0630] Send ERROR\r\n");
								}
							}
							ret = pdPASS;
						}
					}

					/*将FLASH中的数据进行读取*/
					#if (OS_HISTORY_VEHICLE_INFO_REPORT == 1)	
					if( (national808_send_state == N808_SEND_INIT) ||(national808_send_state == N808_SENDRSP_OK) )
					{
						memset(txbuf,0,sizeof(txbuf));
						txbuflen = 0;
						data_len = gaoz_save_data_read( sfb_handle_id , txbuf , &txbuflen );
						if( ( data_len != 0 ) && ( data_len < 0xFFFFFFFF ) )
						{ 	
							memset(national808_data_st.send_data,0,UNIT_FLASH_DATA_LEN);
							national808_data_st.send_datalen = 0;
							if(txbuflen <= UNIT_FLASH_DATA_LEN)
							{
								memcpy(national808_data_st.send_data,txbuf , txbuflen );
								national808_data_st.send_datalen = txbuflen;
								national808_send_state = N808_SEND_WAIT;
							}
							gaoz_log_debug_printf(INFOR_MODE,"800b","sleep gaoz_save_data_read ret: %d,txbuflen:%d\r\n",data_len,txbuflen);
						}
						else
						{
							//gaoz_log_debug_printf(INFOR_MODE,"800b","sleep gaoz_save_data_read ret:%ld\r\n",data_len);
							if( data_len == 0xFFFFFFFF )
							{
								if(n808_cle_save_data() != pdPASS)
								{
									gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]n808_cle_save_data fail\r\n",__FUNCTION__, __LINE__);
								}
							}
							if( wakeup_source_get() == POWER_TIME )
							{
								wakeup_source_set( POWER_INIT );
							}
						}
					}
					#endif
					/*数据读取成功，进行网络数据发送*/
					if(( national808_send_state == N808_SEND_WAIT ) || ( national808_send_state == N808_SEND_OK ))
					{
						//ret = gaoz_socket_write( &socket_handle_1 , national808_data_st.send_data , national808_data_st.send_datalen );
						if( gaoz_socket_write( &socket_handle_1 , national808_data_st.send_data , national808_data_st.send_datalen ) == pdPASS )
						{
							if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
							{   
								*send_st = PLAT_SEND_OK;
								*recv_st = PLAT_HAVE_RESPONSE;	
								national808_send_state = N808_SEND_OK;
								wakeup_source_set( POWER_INIT );
								gaoz_log_debug_printf(INFOR_MODE,"800b","sleep positioninfo:[0504] Send OK\r\n");	
							}
							else
							{
								*send_st = PLAT_SEND_ERR;
								gaoz_log_debug_printf(INFOR_MODE,"800b","sleep positioninfo:[0504] Send ERROR\r\n");	
							}
						}
						else
						{
							*send_st = PLAT_SEND_ERR;
							gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
						}
						ret = pdPASS;
					}
					else
					{
						if( wakeup_source_get() == POWER_RTC 
						||  wakeup_source_get() == POWER_TIME)	
						{
							memset(txbuf,0,sizeof(txbuf));
							txbuflen = SendHeart(txbuf);
							//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
							if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
							{
								if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
								{   
									*send_st = PLAT_SEND_OK;
									*recv_st = PLAT_HAVE_RESPONSE;	
									wakeup_source_set( POWER_INIT );
									gaoz_log_debug_printf(INFOR_MODE,"800b","sleep SendHeart:[0506] Send OK\r\n");	
								}
								else
								{
									*send_st = PLAT_SEND_ERR;
									gaoz_log_debug_printf(INFOR_MODE,"800b","sleep SendHeart:[0506] Send ERROR\r\n");
								}
								national808_herat_time_tick = gaoz_get_systick();	
							}
							else
							{
								*send_st = PLAT_SEND_ERR;
								gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
							}
							ret = pdPASS;
						}						
					}
					gaoz_power_man_wakeup_task_num_stop();
				}
			}	
		}	
		break;
		/*终端设备登出*/
		case TER_RUNING_LOGOUT:	
			national808_net_runing_state_set( TER_RUNING_INIT );
			net_rst = NET_RST_END;
		break;
		/*平台查询系统版本号 成功*/
		case TER_RUNING_VERSION_TRUE:
			memset(txbuf,0,sizeof(txbuf));
			txbuflen = property(txbuf); 
			//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
			if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
			{
				if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
				{   
					*send_st = PLAT_SEND_OK;
					*recv_st = PLAT_NO_RESPONSE;	
					gaoz_log_debug_printf(INFOR_MODE,"800b","property:[0107] Send OK\r\n");	
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","property:[0107] Send ERROR\r\n");	
				}
			}
			else
			{
				*send_st = PLAT_SEND_ERR;
				gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
			}
			national808_net_runing_state_set( TER_RUNING_DATA );
			ret = pdPASS;
		break;
		/*平台查询版本号 失败*/
		case TER_RUNING_VERSION_FAIL:
			
		break;
		/*车辆运行OTA控制*/
		case TER_RUNING_CONTROL_FOTA_TRUE:
			if( national808_net_devres_queue_get( &devres_msg , 1000 ) == pdPASS )
			{	
				gaoz_log_debug_printf(INFOR_MODE,"800b","devres_msg : %d,%d,%d\r\n",devres_msg.respondcmd,devres_msg.respondsn,devres_msg.respondsta);	
				memset(txbuf,0,sizeof(txbuf));
				txbuflen = generalrespond(&devres_msg ,txbuf);
				//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
				if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
				{
					if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
					{   
						*send_st = PLAT_SEND_OK;
						*recv_st = PLAT_NO_RESPONSE;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9108] Send OK\r\n");		
					}
					else
					{
						*send_st = PLAT_SEND_ERR;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9108] Send ERROR\r\n");	
					}
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
				}
				ret = pdPASS;
			}
			else
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_get( &devres_msg , 1000 ) fail\r\n");		
			}
			national808_net_runing_state_set( TER_RUNING_DATA );			
		break;
		case TER_RUNING_CONTROL_FOTA_FAIL:
			
		break;
		/*车辆运行双闪控制*/
		case TER_RUNING_CONTROL_FLASHING_TRUE:
			if( national808_net_devres_queue_get( &devres_msg , 1000 ) == pdPASS )
			{	
				gaoz_log_debug_printf(INFOR_MODE,"800b","devres_msg : %d,%d,%d\r\n",devres_msg.respondcmd,devres_msg.respondsn,devres_msg.respondsta);	
				memset(txbuf,0,sizeof(txbuf));
				txbuflen = generalrespond(&devres_msg ,txbuf);
				//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
				if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
				{
					if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
					{   
						*send_st = PLAT_SEND_OK;
						*recv_st = PLAT_NO_RESPONSE;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9562] Send OK\r\n");	
						if(vehiclect_runing_state_get() == CARCTL_RUNING_INIT)	
						{
							vehiclect_runing_state_set(CARCTL_RUNING_SPEAK_LIGHT);/*鸣笛闪灯状态*/
						}		
						else
						{
							national808_ctrllock_state_set(CTLOCK_OK);
						}
					}
					else
					{
						*send_st = PLAT_SEND_ERR;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9562] Send ERROR\r\n");	
					}
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
				}
				ret = pdPASS;
			}
			else
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_get( &devres_msg , 1000 ) fail\r\n");		
			}
			national808_ctrllock_state_set( CTLOCK_OK);
			national808_net_runing_state_set( TER_RUNING_DATA );
		break;
		case TER_RUNING_CONTROL_FLASHING_FAIL:
			
		break;
		/*车辆运行定位车辆控制*/
		case TER_RUNING_CONTROL_LOCATE_TRUE:
			
		break;
		case TER_RUNING_CONTROL_LOCATE_FAIL:
			
		break;
		/*车辆运行空调控制*/
		case TER_RUNING_CONTROL_AIR_COND_TRUE:

		break;
		case TER_RUNING_CONTROL_AIR_COND_FAIL:
		
		break;
		/*车辆运行车锁控制*/
		case TER_RUNING_CONTROL_DOOR_TRUE:
			if( national808_net_devres_queue_get( &devres_msg , 1000 ) == pdPASS )
			{	 
				gaoz_log_debug_printf(INFOR_MODE,"800b","devres_msg : %d,%d,%d\r\n",devres_msg.respondcmd,devres_msg.respondsn,devres_msg.respondsta);	
				memset(txbuf,0,sizeof(txbuf));
				txbuflen = generalrespond(&devres_msg ,txbuf);
				//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
				if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
				{ 
					if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
					{   
						*send_st = PLAT_SEND_OK;
						*recv_st = PLAT_NO_RESPONSE;	
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9563] Send OK,Control Door Ture\r\n");	
						if(vehiclect_runing_state_get() == CARCTL_RUNING_INIT)
						{ 
							vehiclect_runing_state_set(CARCTL_RUNING_LOCK_UNLOCK);/*控锁状态*/	
						}
						else 
						{
							national808_ctrllock_state_set( CTLOCK_OK);
						}
					}
					else
					{
						*send_st = PLAT_SEND_ERR;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9563] Send ERROR,Control Door Ture\r\n");	
					}
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
				}
				ret = pdPASS;
			}
			else
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_get( &devres_msg , 1000 ) fail\r\n");		
			}
			national808_ctrllock_state_set( CTLOCK_OK);
			national808_net_runing_state_set( TER_RUNING_DATA );
		break;
		case TER_RUNING_CONTROL_DOOR_FAIL:
			if( national808_net_devres_queue_get( &devres_msg , 1000 ) == pdPASS )
			{
				memset(txbuf,0,sizeof(txbuf));
				txbuflen = generalrespond(&devres_msg ,txbuf);
				//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
				if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
				{
					if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
					{   
						*send_st = PLAT_SEND_OK;
						*recv_st = PLAT_NO_RESPONSE;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9563] Send OK,Control Door Fail\r\n");		
					}
					else
					{
						*send_st = PLAT_SEND_ERR;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9563] Send ERROR,Control Door Fail\r\n");	
					}
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
				}
				ret = pdPASS;
			}	
			national808_net_runing_state_set( TER_RUNING_DATA );
			//national808_set_time_tick = gaoz_get_systick(); /*获取当前最新的系统时钟*/
			national808_herat_time_tick = gaoz_get_systick();
		break;
		/*车辆运行发动机控制*/
		case TER_RUNING_CONTROL_ENGINE_TRUE:
		
		break;
		case TER_RUNING_CONTROL_ENGINE_FAIL:
			
		break;
		/*车辆运行车窗控制*/
		case TER_RUNING_CONTROL_WIND_TRUE:
			if( national808_net_devres_queue_get( &devres_msg , 1000 ) == pdPASS )
			{	
				//gaoz_log_debug_printf(INFOR_MODE,"800b","devres_msg : %d,%d,%d\r\n",devres_msg.respondcmd,devres_msg.respondsn,devres_msg.respondsta);	
				memset(txbuf,0,sizeof(txbuf));
				txbuflen = generalrespond(&devres_msg ,txbuf);
				//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
				if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
				{
					if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
					{   
						*send_st = PLAT_SEND_OK;
						*recv_st = PLAT_NO_RESPONSE;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9584] Send OK\r\n");	
						if(vehiclect_runing_state_get() == CARCTL_RUNING_INIT)	
						{
							vehiclect_runing_state_set(CARCTL_RUNING_WIND);/*天窗/升降玻璃*/
						}		
						else
						{
							national808_ctrllock_state_set(CTLOCK_OK);
						}
					}
					else
					{
						*send_st = PLAT_SEND_ERR;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9584] Send ERROR\r\n");	
					}
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
				}
				ret = pdPASS;
			}
			else
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_get( &devres_msg , 1000 ) fail\r\n");		
			}
			national808_ctrllock_state_set( CTLOCK_OK);
			national808_net_runing_state_set( TER_RUNING_DATA );
		break;
		case TER_RUNING_CONTROL_WIND_FAIL:
			
		break;
		/*车辆运行天窗控制*/
		case TER_RUNING_CONTROL_ROOF_TRUE:
			
		break;
		case TER_RUNING_CONTROL_ROOF_FAIL:
			
		break;
		/*OTA远程升级过程*/
		case TER_RUNING_FOTA_SATRT:
			
		break;
		/*OTA升级中*/
		case TER_RUNING_FOTA_UPGRADE:
			
		break;
		/*通知平台刷新固件*/
		case TER_RUNING_FIRMWARE_SATRT:
			
		break;
		/*本地刷新固件成功*/
		case TER_RUNING_FIRMWARE_SUCCESS:
			
		break;
		/*本地刷新固件失败*/
		case TER_RUNING_FIRMWARE_FAIL:
			
		break;
		/*平台查询系统参数成功*/
		case TER_RUNING_QUERY_SYS_PAR_TRUE:
			if( national808_net_devres_queue_get( &devres_msg , 1000 ) == pdPASS )
			{
				memset(txbuf,0,sizeof(txbuf));
				txbuflen = parameter(&devres_msg, txbuf); 
				//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
				if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
				{
					if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
					{   
						*send_st = PLAT_SEND_OK;
						*recv_st = PLAT_NO_RESPONSE;	
						gaoz_log_debug_printf(INFOR_MODE,"800b","property:[0590] Send OK\r\n");	
					}
					else
					{
						*send_st = PLAT_SEND_ERR;
						gaoz_log_debug_printf(INFOR_MODE,"800b","property:[0590] Send ERROR\r\n");	
					}
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
				}
				ret = pdPASS;
			}
			national808_net_runing_state_set( TER_RUNING_DATA );
		break;
		/*平台参数系统参数失败*/
		case TER_RUNING_QUERY_SYS_PAR_FAIL:
			
		break;	
		/*平台设置系统参数成功*/
		case TER_RUNING_SET_SYS_PAR_TRUE:
			if( national808_net_devres_queue_get( &devres_msg , 1000 ) == pdPASS )
			{	
				gaoz_log_debug_printf(INFOR_MODE,"800b","devres_msg : %d,%d,%d\r\n",devres_msg.respondcmd,devres_msg.respondsn,devres_msg.respondsta);	
				memset(txbuf,0,sizeof(txbuf));
				txbuflen = generalrespond(&devres_msg ,txbuf);
				//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
				if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
				{
					if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
					{   
						*send_st = PLAT_SEND_OK;
						*recv_st = PLAT_NO_RESPONSE;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9529] Send OK\r\n");		
						if(net_rst == NET_RST_START)
						{
							national808_net_runing_state_set( TER_RUNING_LOGOUT );
						}
						else
						{
							national808_net_runing_state_set( TER_RUNING_DATA );
						}
					}
					else
					{
						*send_st = PLAT_SEND_ERR;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9529] Send ERROR\r\n");	
						national808_net_runing_state_set( TER_RUNING_DATA );
					}
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
				}
				ret = pdPASS;
			}
			else
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_get( &devres_msg , 1000 ) fail\r\n");		
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
		break;	
		/*平台设置系统参数失败*/
		case TER_RUNING_SET_SYS_PAR_FAIL:
			if( national808_net_devres_queue_get( &devres_msg , 1000 ) == pdPASS )
			{	
				memset(txbuf,0,sizeof(txbuf));
				txbuflen = generalrespond(&devres_msg ,txbuf);
				//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
				if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
				{
					if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
					{   
						*send_st = PLAT_SEND_OK;
						*recv_st = PLAT_NO_RESPONSE;	
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9529] Send OK\r\n");	
					}
					else
					{
						*send_st = PLAT_SEND_ERR;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9529] Send ERROR\r\n");	
					}
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
				}
				ret = pdPASS;
			}	
			national808_net_runing_state_set( TER_RUNING_DATA );
		break;	
		case TER_RUNING_QUERY_DATA:
			memset(txbuf,0,sizeof(txbuf));
			txbuflen = positioninfo(1,txbuf); 
			//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
			if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
			{
				if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
				{   
					*send_st = PLAT_SEND_OK;
					*recv_st = PLAT_NO_RESPONSE;
					gaoz_log_debug_printf(INFOR_MODE,"800b","positioninfo:[0560] Send OK\r\n");	
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","positioninfo:[0560] Send ERROR\r\n");		
				}
			}
			else
			{
				*send_st = PLAT_SEND_ERR;
				gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
			}
			ret = pdPASS;
			national808_net_runing_state_set( TER_RUNING_DATA );
		break;

		case TER_RUNING_QUERY_DATA_ACTIVE:
			memset(txbuf,0,sizeof(txbuf));
			txbuflen = positioninfo(0,txbuf); 
			//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
			if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
			{
				if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
				{   
					*send_st = PLAT_SEND_OK;
					*recv_st = PLAT_NO_RESPONSE;
					gaoz_log_debug_printf(INFOR_MODE,"800b","positioninfo:[0504] Send OK\r\n");	
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","positioninfo:[0504] Send ERROR\r\n");		
				}
			}
			else
			{
				*send_st = PLAT_SEND_ERR;
				gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
			}
			ret = pdPASS;
			national808_net_runing_state_set( TER_RUNING_DATA );
		break;

		case TER_RUNING_CONTROL_BT:
			if( national808_net_devres_queue_get( &devres_msg , 1000 ) == pdPASS )
			{	
				memset(txbuf,0,sizeof(txbuf));
				txbuflen = generalrespond(&devres_msg ,txbuf);
				//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
				if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
				{
					if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
					{   
						*send_st = PLAT_SEND_OK;
						*recv_st = PLAT_NO_RESPONSE;	
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9579] Send OK\r\n");	
					}
					else
					{
						*send_st = PLAT_SEND_ERR;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9579] Send ERROR\r\n");	
					}
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
				}
				ret = pdPASS;
			}	
			national808_net_runing_state_set( TER_RUNING_DATA );
		break;
		case TER_RUNING_GENERAL_RSP:
			if( national808_net_devres_queue_get( &devres_msg , 1000 ) == pdPASS )
			{	
				memset(txbuf,0,sizeof(txbuf));
				txbuflen = generalrespond(&devres_msg ,txbuf);
				//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
				if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
				{
					if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
					{   
						*send_st = PLAT_SEND_OK;
						*recv_st = PLAT_NO_RESPONSE;	
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[0520] Send OK\r\n");
						if( (devres_msg.respondcmd == 0x9565) && (devres_msg.respondsta == 0) )
						{
							if(vehiclect_runing_state_get() == CARCTL_RUNING_INIT)
							{
								vehiclect_runing_state_set(CARCTL_RUNING_RELAY);/*断电状态*/
							}
						}
						else if( (devres_msg.respondcmd == 0x9103) && (devres_msg.respondsta == 0) )
						{
							if(vehiclect_runing_state_get() == CARCTL_RUNING_INIT)
							{
								vehiclect_runing_state_set(CARCTL_RUNING_MAINTENANCE_INFOR_SET);/*保养信息设置*/
							}
						}
					}
					else
					{
						*send_st = PLAT_SEND_ERR;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[0520] Send ERROR\r\n");
					}
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
				}
				if(devres_msg.respondcmd == 0x9571)
				{
					if( *send_st == PLAT_SEND_OK )
					{ 
						national808_net_runing_state_set( TER_RUNING_AUTH );
						memcpy(curinf.ManageID,taginf.ManageID,6);
						national808_send_state = N808_SENDRSP_OK;//切换以后重新读发送数据
					}
				}
				else
				{
					national808_net_runing_state_set( TER_RUNING_DATA );	
				}
				ret = pdPASS;
			}

			if( *send_st != PLAT_SEND_OK )
			{
				national808_net_runing_state_set( TER_RUNING_DATA );
				memcpy(curinf.ManageID,taginf.ManageID,6);
			}
		break;
		case TER_RUNING_QUERY_RSA:
			if( national808_net_devres_queue_get( &devres_msg , 1000 ) == pdPASS )
			{	
				memset(txbuf,0,sizeof(txbuf));
				txbuflen = rsarespond(&devres_msg ,txbuf);
				//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
				if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
				{
					if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
					{   
						*send_st = PLAT_SEND_OK;
						*recv_st = PLAT_NO_RESPONSE;	
						gaoz_log_debug_printf(INFOR_MODE,"800b","rsarespond:[0581] Send OK\r\n");	
					}
					else
					{
						*send_st = PLAT_SEND_ERR;
						gaoz_log_debug_printf(INFOR_MODE,"800b","rsarespond:[0581] Send REEOE\r\n");	
					}
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
				}
				ret = pdPASS;
			}	
			national808_net_runing_state_set( TER_RUNING_DATA );
		break;
		case TER_RUNING_QUERY_QXWZ:
			if( national808_net_devres_queue_get( &devres_msg , 1000 ) == pdPASS )
			{	
				memset(txbuf,0,sizeof(txbuf));
				txbuflen = qxwzrespond(&devres_msg ,txbuf);
				//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
				if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
				{
					if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
					{   
						*send_st = PLAT_SEND_OK;
						*recv_st = PLAT_NO_RESPONSE;	
						gaoz_log_debug_printf(INFOR_MODE,"800b","rsarespond:[0636] Send OK\r\n");	
					}
					else
					{
						*send_st = PLAT_SEND_ERR;
						gaoz_log_debug_printf(INFOR_MODE,"800b","rsarespond:[0636] Send ERROR\r\n");		
					}
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
				}
				ret = pdPASS;
			}	
			national808_net_runing_state_set( TER_RUNING_DATA );
		break;
		case TER_RUNING_CONTROL_PKEKEY:
			if( national808_net_devres_queue_get( &devres_msg , 1000 ) == pdPASS )
			{	
				memset(txbuf,0,sizeof(txbuf));
				txbuflen = pkekeyrsp(&devres_msg ,txbuf);
				//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
				if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
				{
					if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
					{   
						*send_st = PLAT_SEND_OK;
						*recv_st = PLAT_NO_RESPONSE;	
						gaoz_log_debug_printf(INFOR_MODE,"800b","[0605] Send OK \r\n");	
					}
					else
					{
						*send_st = PLAT_SEND_ERR;
						gaoz_log_debug_printf(INFOR_MODE,"800b","[0605] Send ERROR\r\n");	
					}
				}
				else 
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
				}
				ret = pdPASS;
			}	
			national808_net_runing_state_set( TER_RUNING_DATA );
		break;	
		case TER_RUNING_UPLOAD_PKEKEY:
			memset(txbuf,0,sizeof(txbuf));
			txbuflen = pkekeyupload(txbuf);
			//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
			if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
			{
				if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
				{   
					*send_st = PLAT_SEND_OK;
					*recv_st = PLAT_NO_RESPONSE;	
					gaoz_log_debug_printf(INFOR_MODE,"800b","[0637] Send OK \r\n");	
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","[0637] Send ERROR \r\n");	
				}
			}
			else
			{
				*send_st = PLAT_SEND_ERR;
				gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
			}
			ret = pdPASS;
			national808_net_runing_state_set( TER_RUNING_DATA );
		break;	
		case TER_RUNING_QUERY_PKEKEY:
			memset(txbuf,0,sizeof(txbuf));
			txbuflen = querypkekey(txbuf);
			//ret = gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen );
			if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
			{
				if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
				{   
					*send_st = PLAT_SEND_OK;
					*recv_st = PLAT_HAVE_RESPONSE;	
					gaoz_log_debug_printf(INFOR_MODE,"800b","querypkekey:[0601] Send OK \r\n");	
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","querypkekey:[0601] Send ERROR \r\n");	
				}
			}
			else
			{
				*send_st = PLAT_SEND_ERR;
				gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
			}
			ret = pdPASS;
		break;	
		case TER_RUNING_DATA_TRANSFER:	/*网络数据透传，使用用亿华项目*/
			memset( txbuf, 0, sizeof(txbuf) );
			txbuflen = network_data_transmission( txbuf );
			if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
			{
				if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
				{   
					*send_st = PLAT_SEND_OK;
					*recv_st = PLAT_NO_RESPONSE;	
					gaoz_log_debug_printf(INFOR_MODE,"800b","Network data transparent transmission:[0612] Send OK \r\n");	
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","Network data transparent transmission:[0612] Send ERROR \r\n");	
				}
			}
			else
			{
				*send_st = PLAT_SEND_ERR;
				gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
			}
			ret = pdPASS;
			national808_net_runing_state_set( TER_RUNING_DATA );
		break;
		/*网络数据透传成功失败网络数据应答处理*/
		case TER_RUNING_DATA_DOWN_TRUE:
			if( national808_net_devres_queue_get( &devres_msg , 1000 ) == pdPASS )
			{
				memset(txbuf,0,sizeof(txbuf));
				txbuflen = generalrespond(&devres_msg ,txbuf);
				if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
				{
					if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
					{   
						*send_st = PLAT_SEND_OK;
						*recv_st = PLAT_NO_RESPONSE;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9613] Send OK\r\n");
						if(vehiclect_runing_state_get() == CARCTL_RUNING_INIT)
						{
							vehiclect_runing_state_set(CARCTL_RUNING_SETODO);
						}
					}
					else
					{
						*send_st = PLAT_SEND_ERR;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9613] Send ERROR\r\n");	
						national808_net_runing_state_set( TER_RUNING_DATA );
					}
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
				}
				ret = pdPASS;
			}
			else
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_get( &devres_msg , 1000 ) fail\r\n");		
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
			national808_net_runing_state_set( TER_RUNING_DATA );
		break;
		case TER_RUNING_DATA_DOWN_FAIL:
			if( national808_net_devres_queue_get( &devres_msg , 1000 ) == pdPASS )
			{	
				memset(txbuf,0,sizeof(txbuf));
				txbuflen = generalrespond(&devres_msg ,txbuf);
				if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
				{
					if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
					{   
						*send_st = PLAT_SEND_OK;
						*recv_st = PLAT_NO_RESPONSE;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9613] Send OK\r\n");		
					}
					else
					{
						*send_st = PLAT_SEND_ERR;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9613] Send ERROR\r\n");	
						national808_net_runing_state_set( TER_RUNING_DATA );
					}
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
				}
				ret = pdPASS;
			}
			else
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_get( &devres_msg , 1000 ) fail\r\n");		
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
			national808_net_runing_state_set( TER_RUNING_DATA );
		break;
		case TER_RUNING_START_ENGINE_RESP:	/*一键启动通用应答*/
			if( national808_net_devres_queue_get( &devres_msg , 1000 ) == pdPASS )
			{
				memset(txbuf,0,sizeof(txbuf));
				txbuflen = generalrespond(&devres_msg ,txbuf);
				if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
				{
					if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
					{   
						*send_st = PLAT_SEND_OK;
						*recv_st = PLAT_NO_RESPONSE;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9595] Send OK\r\n");
						if(vehiclect_runing_state_get() == CARCTL_RUNING_INIT)
						{
							vehiclect_runing_state_set(CARCTL_RUNING_STARTPOWER);
						}
					}
					else
					{
						*send_st = PLAT_SEND_ERR;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9595] Send ERROR\r\n");	
						national808_net_runing_state_set( TER_RUNING_DATA );
					}
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
				}
				ret = pdPASS;
			}
			else
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_get( &devres_msg , 1000 ) fail\r\n");		
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
			national808_net_runing_state_set( TER_RUNING_DATA );
		break;
		case TER_RUNING_START_ENGINE_RESULT:	/*一键启动处理结果应答*/
			memset( txbuf, 0, sizeof(txbuf) );
			txbuflen = network_data_engine_start_transmission( txbuf );
			if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
			{
				if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
				{
					*send_st = PLAT_SEND_OK;
					*recv_st = PLAT_NO_RESPONSE;	
					gaoz_log_debug_printf(INFOR_MODE,"800b","Network data transparent transmission:[0595] Send OK \r\n");	
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","Network data transparent transmission:[0595] Send ERROR \r\n");	
				}
			}
			else
			{
				*send_st = PLAT_SEND_ERR;
				gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
			}
			ret = pdPASS;
			national808_net_runing_state_set( TER_RUNING_DATA );
		break;
		case TER_RUNING_FAULT_CODE_QUERY_RESP:
			if( national808_net_devres_queue_get( &devres_msg , 1000 ) == pdPASS )
			{
				memset(txbuf,0,sizeof(txbuf));
				txbuflen = generalrespond(&devres_msg ,txbuf);
				if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
				{
					if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
					{   
						*send_st = PLAT_SEND_OK;
						*recv_st = PLAT_NO_RESPONSE;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9599] Send OK\r\n");
						if(vehiclect_runing_state_get() == CARCTL_RUNING_INIT)
						{
							vehiclect_runing_state_set(CARCTL_RUNING_FUALT_CODE_QUERY);
						}
					}
					else
					{
						*send_st = PLAT_SEND_ERR;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9599] Send ERROR\r\n");	
						national808_net_runing_state_set( TER_RUNING_DATA );
					}
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
				}
				ret = pdPASS;
			}
			else
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_get( &devres_msg , 1000 ) fail\r\n");		
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
			national808_net_runing_state_set( TER_RUNING_DATA );
		break;
		case TER_RUNING_FAULT_CODE_CLEAR_RESP:
			if( national808_net_devres_queue_get( &devres_msg , 1000 ) == pdPASS )
			{
				memset(txbuf,0,sizeof(txbuf));
				txbuflen = generalrespond(&devres_msg ,txbuf);
				if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
				{
					if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
					{   
						*send_st = PLAT_SEND_OK;
						*recv_st = PLAT_NO_RESPONSE;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9600] Send OK\r\n");
						if(vehiclect_runing_state_get() == CARCTL_RUNING_INIT)
						{
							vehiclect_runing_state_set(CARCTL_RUNING_FUALT_CODE_CLEAR);
						}
					}
					else
					{
						*send_st = PLAT_SEND_ERR;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9600] Send ERROR\r\n");	
						national808_net_runing_state_set( TER_RUNING_DATA );
					}
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
				}
				ret = pdPASS;
			}
			else
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_get( &devres_msg , 1000 ) fail\r\n");		
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
			national808_net_runing_state_set( TER_RUNING_DATA );
		break;
		case TER_RUNING_FAULT_CODE_INFOR_SEND:
			memset( txbuf, 0, sizeof(txbuf) );
			txbuflen = network_data_fault_code_transmission( txbuf );
			if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
			{
				if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
				{
					*send_st = PLAT_SEND_OK;
					*recv_st = PLAT_HAVE_RESPONSE;	
					gaoz_log_debug_printf(INFOR_MODE,"800b","Network data transparent transmission:[0102] Send OK \r\n");	
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","Network data transparent transmission:[0102] Send ERROR \r\n");	
				}
			}
			else
			{
				*send_st = PLAT_SEND_ERR;
				gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
			}
			ret = pdPASS;
			national808_net_runing_state_set( TER_RUNING_DATA );
		break;

		case TER_RUNING_VEHICLE_DTC_CODE_REPORT:
			memset( txbuf, 0, sizeof(txbuf) );
			gaoz_log_debug_printf(INFOR_MODE,"800b","mcu debug rev 2017 - 0x22 read vehicle dtc code len:[%d]\r\n",txbuflen);
			
			txbuflen = network_data_vehicle_fault_code_transmission( txbuf );
			gaoz_log_debug_printf(INFOR_MODE,"800b","mcu debug rev 2017 - 0x22 read vehicle dtc code len:[%d]\r\n",txbuflen);
			
			if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
			{
				if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
				{
					*send_st = PLAT_SEND_OK;
					*recv_st = PLAT_HAVE_RESPONSE;	
					gaoz_log_debug_printf(INFOR_MODE,"800b","2017 Network data transparent transmission:[0104] Send OK \r\n");	
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","2017 Network data transparent transmission:[0104] Send ERROR \r\n");	
				}
			}
			else
			{
				*send_st = PLAT_SEND_ERR;
				gaoz_log_debug_printf(INFOR_MODE,"800b","2017 [%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
			}
			ret = pdPASS;
			national808_net_runing_state_set( TER_RUNING_DATA );
			break;
		case TER_RUNING_MAINTENANCE_INFOR_SEND:
			memset( txbuf, 0, sizeof(txbuf) );
			txbuflen = network_data_maintenance_infor_transmission( txbuf );
			if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
			{
				if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
				{
					*send_st = PLAT_SEND_OK;
					*recv_st = PLAT_HAVE_RESPONSE;	
					gaoz_log_debug_printf(INFOR_MODE,"800b","Network data transparent transmission:[0103] Send OK \r\n");	
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","Network data transparent transmission:[0103] Send ERROR \r\n");	
				}
			}
			else
			{
				*send_st = PLAT_SEND_ERR;
				gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
			}
			ret = pdPASS;
			national808_net_runing_state_set( TER_RUNING_DATA );
		break;
		case TER_RUNING_SEED_INFOR_SEND: /*终端上报车辆安全认证SEED*/
			memset( txbuf, 0, sizeof(txbuf) );
			txbuflen = network_data_seed_infor_transmission( txbuf );
			if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
			{
				if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
				{
					*send_st = PLAT_SEND_OK;
					*recv_st = PLAT_HAVE_RESPONSE;	
					gaoz_log_debug_printf(INFOR_MODE,"800b","Network data transparent transmission:[0654] Send OK \r\n");	
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","Network data transparent transmission:[0654] Send ERROR \r\n");	
				}
			}
			else
			{
				*send_st = PLAT_SEND_ERR;
				gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
			}
			ret = pdPASS;
			national808_net_runing_state_set( TER_RUNING_DATA );
		break;
		case TER_RUNING_ADAS_INFOR_SEND:	/*终端上报ADAS实时数据上报周期10S*/
			memset( txbuf, 0, sizeof(txbuf) );
			txbuflen = network_data_adas_infor_transmission( txbuf );
			if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
			{
				if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
				{
					*send_st = PLAT_SEND_OK;
					*recv_st = PLAT_HAVE_RESPONSE;	
					gaoz_log_debug_printf(INFOR_MODE,"800b","Network data transparent transmission:[0655] Send OK \r\n");	
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","Network data transparent transmission:[0655] Send ERROR \r\n");	
				}
			}
			else
			{
				*send_st = PLAT_SEND_ERR;
				gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
			}
			ret = pdPASS;
			national808_net_runing_state_set( TER_RUNING_DATA );
		break;
		case TER_RUNING_RV_POWER_RESP:
			if( national808_net_devres_queue_get( &devres_msg , 1000 ) == pdPASS )
			{	
				memset(txbuf,0,sizeof(txbuf));
				txbuflen = generalrespond(&devres_msg ,txbuf);
				if( gaoz_socket_write( &socket_handle_1 , txbuf , txbuflen ) == pdPASS )
				{
					if( national808_socket_send_data_suc( &socket_state_1 ,1000 ) == pdPASS ) /*检测底层回调函数的结果，是否已经发生成功*/
					{   
						*send_st = PLAT_SEND_OK;
						*recv_st = PLAT_NO_RESPONSE;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9655] Send OK\r\n");
						if(vehiclect_runing_state_get() == CARCTL_RUNING_INIT)
						{
							vehiclect_runing_state_set(CARCTL_RUNING_RV_POWER_CTL);
						}
					}
					else
					{
						*send_st = PLAT_SEND_ERR;
						gaoz_log_debug_printf(INFOR_MODE,"800b","generalrespond:[9655] Send ERROR\r\n");	
						national808_net_runing_state_set( TER_RUNING_DATA );
					}
				}
				else
				{
					*send_st = PLAT_SEND_ERR;
					gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]gaoz_socket_write fail\r\n", __FUNCTION__, __LINE__);
				}
				ret = pdPASS;
			}
			else
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_get( &devres_msg , 1000 ) fail\r\n");		
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
			national808_net_runing_state_set( TER_RUNING_DATA );
		break;
        default:
            break;
	}

	if(ret == pdPASS)
	{
		gaoz_power_man_wakeup_task_num_run(); 
	}

	return ret;
}
/** ****************************************************************************
* @remarks       static uint32_t national_wait_response_result( uint32_t wait_time )
* @brief         国标数据应答状态分析
* @param[in]     wait_time 延时的时间设置 单位ms
* @param[out]    无
* @return        pdPASS 成功 pdFAIL 失败
* @attention     无
*******************************************************************************/
static uint32_t national808_wait_response_result( uint32_t wait_time )
{
	uint32_t ret = pdFAIL;
	national_net_res_msg_t net_res_msg;
	/*{
		uint32_t rdqu = 0;
		rdqu = fibo_queue_space_available(national808_send_patiores_queue);
		gaoz_log_debug_printf(INFOR_MODE,"800b","fibo_queue_space_available national808_send_patiores_queue %d\r\n",rdqu);	
	}*/
	if( national808_net_patiores_queue_get( &net_res_msg , wait_time ) == pdPASS )
	{	/* 解析数据应答的结果 */
	 
		gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_get ok%d,%d\r\n",net_res_msg.commane,net_res_msg.results);	
		national808_data_analytic_fun( &net_res_msg );
		if(net_res_msg.commane == TER_REALTIME_DATA_REQ)
		{
			ret = pdPASS;
		}
		else
		{
			ret = net_res_msg.results;
		}
	}
	else
	{
		gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_get fail\r\n");	
		ret = pdFAIL;
	}
	return ret;
}

/** ****************************************************************************
* @remarks       static uint32_t national_plat_time_delay( uint32_t wait_time )
* @brief         等待平台消息延时功能
* @param[in]     wait_time 延时的时间设置 单位ms
* @param[out]    无
* @return        pdPASS 成功 pdFAIL 失败
* @attention     无
*******************************************************************************/
static uint32_t national808_plat_time_delay( uint32_t wait_time )
{
	uint32_t ret = pdFAIL;
	national_net_res_msg_t net_res_msg;

	if ( national808_net_runing_state_get() == TER_RUNING_DATA )
	{
		if( national808_net_patiores_queue_get( &net_res_msg , wait_time ) == pdPASS )
        {   /* 解析数据应答的结果 */ 
	
            national808_data_analytic_fun( &net_res_msg );
            ret = net_res_msg.results;
			gaoz_log_debug_printf(INFOR_MODE,"800b","national808_data_analytic_fun commane: %d,result:%d\r\n",net_res_msg.commane,net_res_msg.results);
        } 
		else 
		{ 
	
		}
	}
	else
	{	
		gaoz_task_sleep( wait_time ); 
	}
	return ret;
}

/** ****************************************************************************
* @remarks       void national_data_analytic_fun( national_response_e *nat_res)
* @brief         国标数据应答状态分析
* @param[in]     无
* @param[out]    *net_res 网络平台应答结果
* @return        无
* @attention     在系统启动后进行创建
*******************************************************************************/
static void national808_data_analytic_fun( national_net_res_msg_t *net_res)
{
	switch( net_res->commane )
	{	
		/*注册平台*/
		case TER_RESPONSE_REG:		/*注册 平台应答*/
			if( net_res->results == pdPASS )
			{
				gaoz_sys_state_state_set( SYS_REG, SYS_REG_YES ); 
				national808_net_runing_state_set( TER_RUNING_AUTH );
			}
			else
			{
				national808_net_runing_state_set( TER_RUNING_REG );
			}
		break;
		/*鉴权平台*/
		case TER_RESPONSE_AUTH:		/*鉴权 平台应答*/
			if( net_res->results == pdPASS )
			{
				if( national_808_ip_addr_t == INTERNAL_IP_ADDR ) /*判断为内部平台地址时进行获取钥匙码*/
				{
					national808_net_runing_state_set( TER_RUNING_QUERY_PKEKEY );
				}
				else
				{
					national808_net_runing_state_set( TER_RUNING_DATA );
				}
				n808_authsta_set(N808_AUTH_SUCC);
				gaoz_sys_state_state_set( SYS_LAND, SYS_LADN_YES );
				vehicle_authentication_st_set( VEHICLE_AUTH_INIT );
			}
			else
			{ 
				national808_net_runing_state_set( TER_RUNING_AUTH );
				n808_authsta_set(N808_AUTH_FAIL);
			}
		break;		
		/*终端心跳应答*/
		case TER_RESPONSE_HEART: 	/*终端心跳平台应答*/
			if( net_res->results == pdPASS )
			{	
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
			else
			{
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
		break;
		/*终端数据实时数据*/
		case TER_REALTIME_DATA_REQ:	/*实时数据平台应答*/
			if( net_res->results == pdPASS )
			{
				//national808_net_runing_state_set( TER_RUNING_DATA );
				national808_send_state = N808_SENDRSP_OK;
			}
			else
			{	
				//national808_net_runing_state_set( TER_RUNING_DATA );
			#if 0 /*服务器发送异常错误命令时也应该为应答成功*/
				national808_send_state = N808_SEND_WAIT;
			#else
				national808_send_state = N808_SENDRSP_OK;
			#endif
			}
		break;
		/*终端数据补发数据*/
		case TER_RESEND_DATA_REQ: /*补发数据平台应答*/
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
			else
			{	
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
		break;
		/*终端登出应答*/
		case TER_RESPONSE_LOGOUT:
		break;
		/*终端下发查询系统版本号*/
		case TER_QUERY_SYS_VERSION:
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_VERSION_TRUE );
			}
			else
			{	
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
		break;
		/*平台下发控制 -- OTA升级*/
		case TER_CONTROL_TER_FOTA:
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_CONTROL_FOTA_TRUE );
			}
			else
			{	
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
		break;
		/*平台下发控制 -- 双闪鸣笛*/
		case TER_CONTROL_TER_FLASHING_HORNS:
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_CONTROL_FLASHING_TRUE );
			}
			else
			{	
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
		break;
		/*平台下发控制 -- 远程定位车辆*/
		case TER_CONTROL_TER_LOCATE_VEHICLE:
		break;
		/*平台下发控制 -- 远程开始空调*/
		case TER_CONTROL_TER_START_AIR_COND:
		break;
		/*平台下发控制 -- 车门解锁*/
		case TER_CONTROL_TER_DOOR_UNCLOCK:
		break;
		/*平台下发控制 -- 远程启动/熄火发动机*/
		case TER_CONTROL_TER_START_ENGINE:
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_START_ENGINE_RESP );
			}
			else
			{	
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
		break;
		/*平台下发控制 -- 远程升降车窗*/
		case TER_CONTROL_TER_UP_DOWN_WIND:
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_CONTROL_WIND_TRUE );
			}
			else
			{	
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
		break;
		/*平台下发控制 -- 远程天窗控制*/
		case TER_CONTROL_TER_ROOF_OPENING:
		break;
		case TER_CONTROL_TER_BT_UPDATESE:
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_CONTROL_BT );
			}
			else
			{	
				national808_net_runing_state_set( TER_RUNING_CONTROL_BT );
			}
		break;
		case TER_CONTROL_TER_QXWZKEY_SET:
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_GENERAL_RSP );
			}
			else
			{	
				national808_net_runing_state_set( TER_RUNING_GENERAL_RSP );
			}
		break;
		case TER_CONTROL_TER_QXWZKEY_CLE:
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_GENERAL_RSP );
			}
			else
			{	
				national808_net_runing_state_set( TER_RUNING_GENERAL_RSP );
			}
		break;
		case TER_CONTROL_TER_UPDATE_ID:
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_GENERAL_RSP );
			}
			else
			{	
				national808_net_runing_state_set( TER_RUNING_GENERAL_RSP );
			}
		break;
		case TER_CONTROL_TER_POWER:
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_GENERAL_RSP );
			}
			else
			{	
				national808_net_runing_state_set( TER_RUNING_GENERAL_RSP );
			}
		break;
		case TER_CONTROL_TER_PKEKEY:
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_CONTROL_PKEKEY );
			}
			else
			{	
				national808_net_runing_state_set( TER_RUNING_CONTROL_PKEKEY );
			}
		break;
		/***********************************************************************************************/
		/*FOTA开始下载固件*/
		case TER_FOTA_DOWNLOAD_START:
		break;	
		case TER_FOTA_DOWNLOAD_STOP:
		break;	
		/***********************************************************************************************/
		/*固件下载成功*/
		case TER_FOTA_DOWNLOAD_SUCCESS:
		break;		
		/*固件升级失败*/
		case TER_FOTA_DOWNLOAD_ERR:
		break;
		/***********************************************************************************************/
		/*开始升级固件 成功*/
		case TER_FOTA_FIRMWARE_START:
		break;
		/*开始升级固件 失败*/
		case TER_FOTA_FIRMWARE_STOP:
		break;
		/***********************************************************************************************/
		/*应答本地升级固件 成功*/
		case TER_FOTA_FIRMWARE_SUCCESS:
		break;
		/*应答本地升级固件 失败*/
		case TER_FOTA_FIRMWARE_ERR:
		break;
		/*应答本地升级固件 超时*/	
		case TER_FOTA_FIRMWARE_TIME_OUT:
		break;
		case TER_QUERY_SYS_PARRMETER:
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_QUERY_SYS_PAR_TRUE );
			}
			else
			{	
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
		break;
		case TER_SET_SYS_PARRMETER:
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_SET_SYS_PAR_TRUE );
			}
			else
			{	
				national808_net_runing_state_set( TER_RUNING_SET_SYS_PAR_FAIL );
			}
		break;
		case TER_QUERY_REALTIME:
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_QUERY_DATA );
			}
			else
			{	
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
		break;
		case TER_QUERY_RSA:
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_QUERY_RSA );
			}
			else
			{	
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
		break;
		case TER_QUERY_QXWZPARA:
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_QUERY_QXWZ );
			}
			else
			{	
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
		break;
		case TER_CONTROL_TERMINAL_ACK: 
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_CONTROL_DOOR_TRUE );
			}
			else
			{	
				national808_net_runing_state_set( TER_RUNING_CONTROL_DOOR_FAIL );
			}
		break;
		case TER_CONTROL_TER_RESET:
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_GENERAL_RSP );
			}
			else
			{	
				national808_net_runing_state_set( TER_RUNING_GENERAL_RSP );
			}
		break;
		case TER_QUERY_PKEKEY:
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_GENERAL_RSP );
			}
			else
			{	
				national808_net_runing_state_set( TER_RUNING_GENERAL_RSP );
			}
		break;
		case TER_RESPONSE_DATA_UP:
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
			else
			{
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
		break;
		case TER_RESPONSE_DATA_DOWN:
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_DATA_DOWN_TRUE );
			}
			else
			{	
				national808_net_runing_state_set( TER_RUNING_DATA_DOWN_FAIL );
			}
		break;
		case TER_FAULT_CODE_QUERY:
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_FAULT_CODE_QUERY_RESP );
			}
			else
			{	
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
		break;
		case TER_FAULT_CODE_CLEAR:
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_FAULT_CODE_CLEAR_RESP );
			}
			else
			{	
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
		break;
		case TER_FAULT_CODE_UPDATA:
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
			else
			{
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
		break;
		case TER_MAINTENANCE_INFOR_SET:
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_GENERAL_RSP );
			}
			else
			{	
				national808_net_runing_state_set( TER_RUNING_GENERAL_RSP );
			}
		break;
		case TER_MAINTENANCE_INFOR_UPDATA:

		break;
		case TER_BMS_INFOR_UPDATA:
			
		break;
		case TER_RV_POWER_CTL:
			if( net_res->results == pdPASS )
			{
				national808_net_runing_state_set( TER_RUNING_RV_POWER_RESP );
			}
			else
			{	
				national808_net_runing_state_set( TER_RUNING_DATA );
			}
		break;
        default:
            break;
	}
}

/** ****************************************************************************
* @remarks      uint32_t gzlable_print(uint8_t *pDa, uint16_t *pDlen) 
* @brief        工装标签信息 
* @param[in]   	无  
* @param[out]    *pDa缓存区，*pDlen长度
* @return        pdPASS成功 ，  pdFAIL失败
* @attention     无
*******************************************************************************/
uint32_t gzlable_print(uint8_t *pDa, uint16_t *pDlen, uint8_t flag) 
{
	uint8_t idx;
	uint8_t term_id[4];
	uint8_t AuthDa[120] = {0};	
	uint8_t ccid[20]={0};
	char btmac[30];
	uint8_t btmac_hex[6]={0};

	idx = 0;
	//终端ID
	memcpy(term_id,terminid, 4);
	memcpy(&AuthDa[idx], term_id, 4);
	idx += 4;

	//car_id
	memcpy(&AuthDa[idx],taginf.ManageID, 6);
	idx += 6;

	//MAC
	ble_drive_macaddr_read(btmac);
	// memcpy( (uint8_t *)btmac, (uint8_t *)gaoz_ble_drive_macaddr_infor_get(), BLE_DEVICE_MAC_LEN );
	gaoz_log_debug_printf(INFOR_MODE,"800b","gaoz_ble_drive_macaddr_infor_get() : %s\r\n",btmac);
	ASCIImac2Hex((uint8_t *)btmac,strlen(btmac),btmac_hex);
	AuthDa[idx++] = btmac_hex[5];
	AuthDa[idx++] = btmac_hex[4];
	AuthDa[idx++] = btmac_hex[3];
	AuthDa[idx++] = btmac_hex[2];
	AuthDa[idx++] = btmac_hex[1];
	AuthDa[idx++] = btmac_hex[0];

	net_module_run_state_get( MOD_CCID, (uint8_t *)ccid);
	memcpy(&AuthDa[idx], ccid, 20);
	idx += 20;

	if(flag == 1)
	{
		//APP版本号
		memcpy(&AuthDa[idx], OS_SOFTWARE_VERSION, 30);
		idx += 30;

		//MCU版本号
		memcpy(&AuthDa[idx], get_mcuversion(), S_VER_LEN);
		idx += S_VER_LEN;

		//蓝牙版本号0000
		 memcpy( (uint8_t *)&AuthDa[idx], "0000000000000000000000", 22);
		 idx += 22;
	}
	
	memcpy(pDa,AuthDa,idx);
	*pDlen = idx;

	return pdPASS;
}
/** ****************************************************************************
* @remarks      uint32_t gzlable_eraseid(void)
* @brief         工装擦除id
* @param[in]     无
* @param[out]    无
* @return        pdPASS成功 ，  pdFAIL失败
* @attention     无
*******************************************************************************/
uint32_t gzlable_eraseid(void)
{
	uint32_t ret = pdFAIL;
	int fret = 0;

	//net_1
	int fd = fibo_file_open(TERMID_FILE,FS_O_RDONLY);
	if(fd < 0)
	{
		gaoz_log_debug_printf(INFOR_MODE,"800b","fibo_file_open(TERMID_FILE fail!!");
		ret = pdFAIL;
	}
	else
	{
		fret = fibo_file_close(fd);
		if(fret < 0)
		{
			gaoz_log_debug_printf(INFOR_MODE,"800b","fibo_file_close fail!!");
			ret = pdFAIL;
		} 
		else
		{
			fret = fibo_file_delete(TERMID_FILE);
			if(fret < 0)
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","fibo_file_delete fail!!");
				ret = pdFAIL;
			} 
			else
			{
				ret = flash_spi_sector_erase(SF_SYS_PARA_FLAG_ADDR);
				if(ret == pdPASS)
				{
					ret = flash_spi_sector_erase(SF_SYS_PARA_BACKUP_ADDR);
				}
			}
		}
	}

	//net_2
	int fd1 = fibo_file_open(MANGPATIOR_FILE,FS_O_RDONLY);
	if(fd1 < 0)
	{
		OSI_PRINTFI("fibo_file_open(MANGPATIOR_FILE fail!!");
		ret = pdFAIL;
	}
	else
	{
		fret = fibo_file_close(fd1);
		if(fret < 0)
		{
			OSI_PRINTFI("fibo_file_close fail!!");
			ret = pdFAIL;
		} 
		else
		{
			fret = fibo_file_delete(MANGPATIOR_FILE);
			if(fret < 0)
			{
				OSI_PRINTFI("fibo_file_delete fail!!");
				ret = pdFAIL;
			} 
		}
	}

	return ret;
}
/** ****************************************************************************
* @remarks      uint32_t gzlable_exchangeip(uint8_t *pDa, uint16_t pDlen)
* @brief         修改IP
* @param[in]     无
* @param[out]    无
* @return        pdPASS成功 ，  pdFAIL失败
* @attention     无
*******************************************************************************/
uint32_t gzlable_exchangeip(uint8_t *pDa, uint16_t pDlen)
{
	#define IP_MALLOC    1024*1
	terminal_info_t current_info={0};
	uint8_t ip_len = 0;
	uint8_t port_len = 0;
	UINT8 check = 0;
	uint32_t ret = pdFAIL;
	if(memcmp(terminid,"\x0\x0\x0\x0",4) == 0)
	{
		return pdFAIL;
	}
	if((pDa == NULL) || (pDlen == 0))
	{
		return pdFAIL;
	}
	char *tmpDa = (char *)fibo_malloc(IP_MALLOC);
	if (tmpDa == NULL)
	{
		return pdFAIL;
	}
	memset(tmpDa,0,IP_MALLOC);
	memcpy(&current_info,&taginf,sizeof(terminal_info_t));//major
	ip_len = (uint8_t)(pDlen>>8);
	port_len = (uint8_t)(pDlen&0xff)-ip_len;
	if (((judgeIpType(pDa, ip_len) == 0) || (get_valid_domain_name((char *)pDa, ip_len) == 0)) && (port_len != 0))
	{
		memset(current_info.IP1,0,sizeof(current_info.IP1));
		memcpy(current_info.IP1, pDa, ip_len);
		current_info.IP1Len = ip_len;
		memset(current_info.IP2,0,sizeof(current_info.IP2));
		memcpy(current_info.IP2, pDa, ip_len);
		current_info.IP2Len = ip_len;
		memcpy(current_info.Port1, &pDa[ip_len], port_len);
		current_info.Port1Len = port_len;
		memcpy(current_info.Port2, &pDa[ip_len], port_len);
		current_info.Port2Len = port_len;
	}
	else
	{
		fibo_free(tmpDa);
		return pdFAIL;
	}
	check = get_chk_xor((uint8_t*)(&current_info), sizeof(terminal_info_t)-1);
	current_info.Check = check;
	memcpy(tmpDa,terminid,4);	
	memcpy(&tmpDa[4],"EDTT",4);
	memcpy(&tmpDa[8],&current_info,sizeof(terminal_info_t));
	ret = file_termpara_write(TERMID_FILE,tmpDa,sizeof(terminal_info_t)+8);
	if(ret < 0)
	{
		fibo_free(tmpDa);	
		return pdFAIL;
	}	
	flash_spi_sector_erase(SF_SYS_PARA_FLAG_ADDR);
	ret = flash_spi_write_data(SF_SYS_PARA_FLAG_ADDR,(uint8_t *)tmpDa,sizeof(terminal_info_t)+8);
	if(ret == pdPASS)
	{
		gaoz_log_debug_printf(INFOR_MODE,"800b",">>SF_SYS_PARA_FLAG_ADDR Okay:%s,%s<<",current_info.IP1,current_info.Port1);
	}
	flash_spi_sector_erase(SF_SYS_PARA_BACKUP_ADDR);
	ret = flash_spi_write_data(SF_SYS_PARA_BACKUP_ADDR,(uint8_t *)tmpDa,sizeof(terminal_info_t)+8);
	if(ret == pdPASS)
	{
		gaoz_log_debug_printf(INFOR_MODE,"800b",">>SF_SYS_PARA_FLAG_ADDR Okay<<");
	}
	fibo_free(tmpDa);
	return ret;
}
/** ****************************************************************************
* @remarks      static uint32_t gzlable_checkidfromflash(void)
* @brief         检查flash是否有参数表备份，flash和文件系统互备份
* @param[in]     无
* @param[out]    无
* @return        pdPASS成功 ，  pdFAIL失败
* @attention     无
*******************************************************************************/
static uint32_t gzlable_checkidfromflash(void)
{
	#define CKIDFR_MALLOC    1024*1
	uint32_t ret = pdFAIL;
	uint16_t tmpDalen = 0;

	char *tmpDa = (char *)fibo_malloc(CKIDFR_MALLOC);
	if (tmpDa == NULL)
	{
		while(1);
	}
	memset(tmpDa,0,CKIDFR_MALLOC);
	tmpDalen = sizeof(terminal_info_t);
	flash_spi_read_data(SF_SYS_PARA_FLAG_ADDR,(uint8_t *)tmpDa,tmpDalen+8);
	if(memcmp(&tmpDa[4],"EDTT", 4) != 0)
	{
		flash_spi_read_data(SF_SYS_PARA_BACKUP_ADDR,(uint8_t *)tmpDa,tmpDalen+8);
		if(memcmp(&tmpDa[4],"EDTT", 4) != 0)
		{
			ret = pdFAIL;
		}
		else
		{
			flash_spi_sector_erase(SF_SYS_PARA_FLAG_ADDR);
			flash_spi_write_data(SF_SYS_PARA_FLAG_ADDR,(uint8_t *)tmpDa,tmpDalen+8);
			ret = file_termpara_write(TERMID_FILE,tmpDa,tmpDalen+8);
			if(ret > 8)
			{
				ret = pdPASS;
			}
			else
			{
				ret = pdFAIL;
			}
		}
	}
	else
	{
		ret = file_termpara_write(TERMID_FILE,tmpDa,tmpDalen+8);
		if(ret > 8)
		{
			ret = pdPASS;
		}
		else
		{
			ret = pdFAIL;
		}
	}
	fibo_free(tmpDa);

	return ret;
}

/** ****************************************************************************
* @remarks      static uint32_t gzlable_checkidtoflash(uint8_t *pda)
* @brief         检查文件系统是否有参数表备份，flash和文件系统互备份
* @param[in]     *pda缓存区
* @param[out]    无
* @return        pdPASS成功 ，  pdFAIL失败
* @attention     无
*******************************************************************************/
static uint32_t gzlable_checkidtoflash(uint8_t *pda)
{
	#define CKIDTO_MALLOC     1024*1
	uint32_t ret = pdFAIL;
	int tmpDalen = 0;

	if(pda == NULL)
	{
		return ret;
	}
	char *tmpDa = (char *)fibo_malloc(CKIDTO_MALLOC);
	if (tmpDa == NULL)
	{
		while(1);	
	}
	memset(tmpDa,0,CKIDTO_MALLOC);
	tmpDalen = sizeof(terminal_info_t);
	flash_spi_read_data(SF_SYS_PARA_FLAG_ADDR,(uint8_t *)tmpDa,tmpDalen+8);
	if(memcmp(&tmpDa[4],"EDTT", 4) != 0)
	{
		gaoz_log_debug_printf(INFOR_MODE,"800b","termid_copy_to_flash ok!\r\n");
		ret = readTerminalPara(TERMID_FILE);
		if(ret < 0)
		{
			initTerminalParaAll(pda,NULL,NULL);//default;
		}
		memset(tmpDa,0,CKIDTO_MALLOC);
		memcpy(tmpDa,pda,4);
		memcpy(&tmpDa[4],"EDTT",4);
		memcpy(&tmpDa[8],&taginf,tmpDalen);
		flash_spi_sector_erase(SF_SYS_PARA_FLAG_ADDR);
		flash_spi_write_data(SF_SYS_PARA_FLAG_ADDR,(uint8_t *)tmpDa,tmpDalen+8);
		fibo_taskSleep(100);	
		flash_spi_sector_erase(SF_SYS_PARA_BACKUP_ADDR);
		flash_spi_write_data(SF_SYS_PARA_BACKUP_ADDR,(uint8_t *)tmpDa,tmpDalen+8);
		ret = pdPASS;
	}
	else //flash和fat不同时，以flash为准
	{
		if(memcmp(tmpDa,pda,4) != 0)
		{
			ret = file_termpara_write(TERMID_FILE,tmpDa,tmpDalen+8);
			if(ret > 8)
			{
				ret = pdPASS;
			}
			else
			{
				ret = pdFAIL;
			}
		}
		else
		{
			ret = pdPASS;
		}
	}
	fibo_free(tmpDa);

	return ret;
}

/** ****************************************************************************
* @remarks       static uint32_t gzlable_check_flash_parameters( void )
* @brief         检测Flash中存储的系统参数
* @param[in]     无
* @param[out]    无
* @return        pdPASS成功, pdFAIL失败
* @attention     无
*******************************************************************************/
static uint32_t gzlable_check_flash_parameters( void )
{
	#define TER_ID_LEN	( 8 )
	#define SAVE_ID_LEN	( 6 )

	uint32_t ret = pdFAIL;
	uint8_t xor = 0;
	uint8_t id_l610 = 0, id_flash = 0, id_backup_flash = 0;
	uint8_t para_l610 = 0, para_flash = 0, para_backup_flash = 0;
	terminal_info_t para_infor = { 0 }, para_backup_para = { 0 };
	terminal_info_t *para_p = NULL;
	uint8_t ter_flash_id[TER_ID_LEN] = { 0 }, ter_backup_id[TER_ID_LEN] = { 0 };
	uint8_t *dev_id_p = NULL;
	uint8_t save_id[SAVE_ID_LEN] = { 0 };
	uint8_t *save_data = NULL;
	uint16_t save_len = 0;
	/*读取L610 文件系统中的系统参数*************************************************************/
	if( readTerminalPara(TERMID_FILE) == 0 )
	{
		xor = get_chk_xor((uint8_t *)&taginf, ( sizeof(terminal_info_t) - 1 ));
		if( xor == taginf.Check )
		{
			if( strlen( (const char *)taginf.IP1 ) == taginf.IP1Len )
			{
				para_l610 = 0x01;
			}
		}
	}
	/*读取外部FLASH 中的系统参数*/
	if( flash_spi_read_data(SF_SYS_PARA_FLAG_ADDR + TER_ID_LEN,(uint8_t *)&para_infor,sizeof(terminal_info_t) ) == pdPASS )
	{
		xor = get_chk_xor((uint8_t *)&para_infor, ( sizeof(terminal_info_t) - 1 ));
		if( xor == para_infor.Check )
		{
			if( strlen( (const char *)para_infor.IP1 ) == para_infor.IP1Len )
			{
				para_flash = 0x01;
			}
		}	
	}
	/*读取外部备份FLASH 中的系统参数*/
	if( flash_spi_read_data(SF_SYS_PARA_BACKUP_ADDR + TER_ID_LEN,(uint8_t *)&para_backup_para,sizeof(terminal_info_t) ) == pdPASS )
	{
		xor = get_chk_xor((uint8_t *)&para_backup_para, ( sizeof(terminal_info_t) - 1 ));
		if( xor == para_backup_para.Check )
		{
			if( strlen( (const char *)para_backup_para.IP1 ) == para_backup_para.IP1Len )
			{
				para_backup_flash = 0x01;
			}
		}
	}

	/*判断读取系统参数是否正确*/
	if(( para_l610 == 0x01 ) && ( para_flash == 0x01 ) && ( para_backup_flash == 0x01 ))
	{
		para_p = (terminal_info_t *)&taginf;
		gaoz_log_debug_printf(INFOR_MODE,"800b","System parameters is verified successfully,can be used\r\n" );
	}
	else 
	{
		if( para_l610 == 0x01 )
		{
			para_p = (terminal_info_t *)&taginf;
		}
		else if( para_flash == 0x01 )
		{
			para_p = (terminal_info_t *)&para_infor;
		}
		else if( para_backup_flash == 0x01 )
		{
			para_p = (terminal_info_t *)&para_backup_para;
		}
		else
		{
			para_p = NULL;
		}
	}

	/*读取L610 文件系统中的设备ID号*******************************************************/
	if( file_termpara_read( TERMID_FILE,(INT8 *)terminid ) == 0 )
	{
		id_l610 = 0x01;
	}
	else
	{
		if( para_l610 == 0x01 )
		{
			para_l610 = 0x00;
		}
	}
	/*读取FLASH中的设备ID号*/
	if( flash_spi_read_data(SF_SYS_PARA_FLAG_ADDR,(uint8_t *)ter_flash_id,TER_ID_LEN ) == pdPASS )
	{
		if( memcmp(&ter_flash_id[4],"EDTT",4) == 0 )
		{
			id_flash = 0x01;
		}
		else
		{
			if( para_flash == 0x01 )
			{
				para_flash = 0x00;
			}
		}
	}
	/*读取备份FLASH中的设备ID号*/
	if( flash_spi_read_data(SF_SYS_PARA_BACKUP_ADDR,(uint8_t *)ter_backup_id,TER_ID_LEN ) == pdPASS )
	{
		if( memcmp(&ter_backup_id[4],"EDTT",4) == 0 )
		{
			id_backup_flash = 0x01;
		}
		else
		{
			if( para_backup_flash == 0x01 )
			{
				para_backup_flash = 0x00;
			}
		}
	}

	/*判断读取设备ID是否正确*/
	if(( id_l610 == 0x01 ) && ( id_flash == 0x01 ) && ( id_backup_flash == 0x01 ))
	{
		if( dev_id_p == NULL )
		{
			if( memcmp( terminid, ter_flash_id, 4 ) == 0 )
			{
				dev_id_p = (uint8_t *)terminid;
				if( memcmp( ter_flash_id, ter_backup_id, 4 ) != 0 )
				{
					id_backup_flash = 0x00;
				}
			}
		}
		if( dev_id_p == NULL )
		{
			if( memcmp( ter_flash_id, ter_backup_id, 4 ) == 0 )
			{
				dev_id_p = (uint8_t *)ter_flash_id;
				if( memcmp( ter_backup_id, terminid, 4 ) != 0 )
				{
					id_l610 = 0x00;
				}
			}
		}
		if( dev_id_p == NULL )
		{
			if( memcmp( ter_backup_id, terminid, 4 ) == 0 )
			{
				dev_id_p = (uint8_t *)ter_backup_id;
				if( memcmp( terminid, ter_flash_id, 4 ) != 0 )
				{
					id_flash = 0x00;
				}
			}
		}
		if(( id_l610 == 0x01 ) && ( id_flash == 0x01 ) && ( id_backup_flash == 0x01 ))
		{
			gaoz_log_debug_printf(INFOR_MODE,"800b","Device ID is verified successfully,can be used\r\n" );	
		}
	}
	else
	{
		if( id_l610 == 0x01 )
		{
			dev_id_p = (uint8_t *)terminid;
		}
		else if( id_flash == 0x01 )
		{
			dev_id_p = (uint8_t *)ter_flash_id;
		}
		else if( id_backup_flash == 0x01 )
		{
			dev_id_p = (uint8_t *)ter_backup_id;
		}
		else
		{
			dev_id_p = NULL;
		}
	}
	
	/*判断设备ID指针是否有效，如果不为NULL表示存储空间中存在存在有效参数*/
	if( dev_id_p != NULL ) 
	{
		save_data = (uint8_t *)gaoz_fibo_malloc( 1024 );
		if ( save_data == NULL )
		{
			return pdFAIL;
		}
		memset( (uint8_t *)save_data, 0x00, 1024 );
		save_id[0] = 0x80;
		save_id[1] = 0x0f&((dev_id_p[0]>>4)&0x0f);
		save_id[2] = (((dev_id_p[0]&0x0f)<<4)&0xf0)|((dev_id_p[1]>>4)&0x0f);
		save_id[3] = (((dev_id_p[1]&0x0f)<<4)&0xf0)|((dev_id_p[2]>>4)&0x0f);
		save_id[4] = (((dev_id_p[2]&0x0f)<<4)&0xf0)|((dev_id_p[3]>>4)&0x0f);
		save_id[5] = (((dev_id_p[3]&0x0f)<<4)&0xf0)&0xf0;
		/*判断系统参数是否有效，不为NULL表示存储空间中存在有效参数，使用其中的ManageID参数*/
		if( para_p != NULL )
		{
			memcpy( (uint8_t *)save_id, (uint8_t *)para_p->ManageID, SAVE_ID_LEN );
		}
		memcpy( (uint8_t *)&save_data[0], (uint8_t *)dev_id_p, 4 );
		memcpy( (uint8_t *)&save_data[4], "EDTT", 4 );
		init_paratable( (uint8_t *)save_id, (uint8_t *)&save_data[8], (uint16_t *)&save_len );
		if((id_l610 == 0x00 ) || ( para_l610 == 0x00 ))
		{
			file_termpara_write( TERMID_FILE,( INT8 *)save_data, save_len+TER_ID_LEN );
			gaoz_log_debug_printf(DEBUG_MODE,"800b","L610 file write:id_l610 = %d,para_l610 = %d\r\n", id_l610, para_l610);
		}
		if(( id_flash == 0x00 ) || ( para_flash == 0x00 ))
		{
			flash_spi_sector_erase(SF_SYS_PARA_FLAG_ADDR);
			flash_spi_write_data( SF_SYS_PARA_FLAG_ADDR,(uint8_t *)save_data, save_len+TER_ID_LEN );
			gaoz_log_debug_printf(DEBUG_MODE,"800b","FLASH file write:id_flash = %d,para_flash = %d\r\n", id_flash, para_flash);		
		}
		if(( id_backup_flash == 0x00 ) || ( para_backup_flash == 0x00 ))
		{
			flash_spi_sector_erase(SF_SYS_PARA_BACKUP_ADDR);
			flash_spi_write_data( SF_SYS_PARA_BACKUP_ADDR, (uint8_t *)save_data, save_len+TER_ID_LEN );
			gaoz_log_debug_printf(DEBUG_MODE,"800b","BACKUP FLASH write:id_backup_flash = %d,para_backup_flash = %d\r\n", id_backup_flash, para_backup_flash );		
		}
		
		gaoz_fibo_free( ( void *)save_data );
		ret = pdPASS;
	}
	
	return ret;
}

/** ****************************************************************************
* @remarks       static void national808_net_control_state_check( void )
* @brief         网络平台控制命令状态检测
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void national808_net_control_state_check( void )
{
	#define NATIONAL808_CHECK_TIME_TICK ( 10 )				/*检测TICK时间10S*/
	static uint32_t national808_check_time_tick = 0;
	
	if( (national808_ctrllock_state_get() != CTLOCK_INIT) && (national808_ctrllock_state_get() != CTLOCK_OK))
	{	
		gaoz_log_debug_printf(DEBUG_MODE,"800b","national808_ctrllock_state_get() == %d\n", national808_ctrllock_state_get() );
		gaoz_power_man_wakeup_task_num_run();				/*防止系统进入休眠状态*/ 
		if( pdPASS == sys_timestamp_delay(( uint32_t * )&national808_check_time_tick, NATIONAL808_CHECK_TIME_TICK * GAOZ_TICK_PERIOD_S ) )
		{
			national808_ctrllock_state_set( CTLOCK_OK );
			gaoz_log_debug_printf(DEBUG_MODE,"800b","national808_ctrllock_state_set( CTLOCK_OK )\n");
		}
		gaoz_power_man_wakeup_task_num_stop();
	}
	else
	{
		national808_check_time_tick = gaoz_get_systick();	/*获取系统tick时钟*/
	}
}

/** ****************************************************************************
* @remarks       void  national808_net_st_check_task( void * param)
* @brief         网络状态监控
* @param[in]     * param 任务参数
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void national808_net_st_check_task(void *param)
{
	int ret = 0;
    INT8 host[64] = {0};	//"47.94.40.171";//"47.93.235.246";//"iothub.xiaojukeji.com";//"116.85.38.210";123.59.168.253
	uint8_t carid[6] = {0};
	uint32_t port1= 0;  	//9666;//40000
	static uint8_t loopcnt = 0;
	/*系统FLASH 参数检测********************************************************/
	gaoz_task_sleep( 1000 ); 							//延迟1S钟等待系统稳定
	gzlable_check_flash_parameters();					//检测系统存储的参数
	/**************************************************************************/
	ret = file_termpara_read(TERMID_FILE,(INT8 *)terminid);
	gaoz_log_debug_printf(INFOR_MODE,"800b","termid_init[%d]\n", ret);
	if((ret == -2)||(ret == -1))
	{
		if(gzlable_checkidfromflash() == pdPASS)
		{
			gaoz_log_debug_printf(INFOR_MODE,"800b","termid_copy_from_flash ok!\n");
		}
		else
		{
			while(1)
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]no termid_init \r\n", __FUNCTION__, __LINE__);	
				gaoz_mon_reset_task_dog();
				if(upgradeid_mutex != 0)
				{
					gaoz_sem_wait( upgradeid_mutex );//等待回应信号量	
					gaoz_sem_free( upgradeid_mutex );
					break;
				}
				else
				{
					gaoz_power_man_wakeup_task_num_run();
					fibo_taskSleep(1000);
					gzlable_operateid(0x12,NULL,0);
				}
			}
		}
	}
	else if(ret == 0)
	{
		gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]termid_init [%02x,%02x,%02x,%02x]", __FUNCTION__, __LINE__,terminid[0],terminid[1],terminid[2],terminid[3]);			
		ret = gzlable_checkidtoflash(terminid);	
		if(ret != pdPASS)
		{
			gaoz_log_debug_printf(INFOR_MODE,"800b","gzlable_checkidtoflash fail!\n");
		}
	}
    //timestamp = osiEpochSecond();
    //gaoz_log_debug_printf(INFOR_MODE,"800b","timestamp[%d]\n", timestamp);
	gaoz_mon_reg_task_dog( 60 * GAOZ_TICK_PERIOD_S ,(uint8_t *)NAT808_SENDTASK_NAME ,TASK_SEM_YES);
	for( ;; )
	{
		gaoz_mon_reset_task_dog();
		{
			ret = file_termpara_read(TERMID_FILE,(INT8 *)terminid);
			if(ret == 0)
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]termid_init [%02x,%02x,%02x,%02x]", __FUNCTION__, __LINE__,terminid[0],terminid[1],terminid[2],terminid[3]);			
				gaoz_task_sleep(1000); 
				ret = -1;
				ret = readTerminalPara(TERMID_FILE);
				/*2022.05.09 YXX 当读取参数文件失败后，需要对参数进行flash数据同步一次，将数据进行重新设置方式数据数据异常*/
				if( ret < 0 )
				{
					if( gzlable_checkidfromflash() == pdPASS )
					{
						ret = readTerminalPara(TERMID_FILE);
					}
				}
				if(ret < 0)
				{
					//增加800头
					carid[0] = 0x80;
					carid[1] = 0x0f&((terminid[0]>>4)&0x0f);
					carid[2] = (((terminid[0]&0x0f)<<4)&0xf0)|((terminid[1]>>4)&0x0f);
					carid[3] = (((terminid[1]&0x0f)<<4)&0xf0)|((terminid[2]>>4)&0x0f);
					carid[4] = (((terminid[2]&0x0f)<<4)&0xf0)|((terminid[3]>>4)&0x0f);
					carid[5] = (((terminid[3]&0x0f)<<4)&0xf0)&0xf0;
					initTerminalParaAll(carid,NULL,NULL);//default;
					log_debug_printf(ERROR_MODE,NAT808_SENDTASK_NAME ,"[%s]get major terminal para fail used default\r\n",sys_err_infor_pointer_get( 50 ));
				}
				else
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]termid_para [%d,%d,%d,%d]", __FUNCTION__, __LINE__,hex4CombineOne(taginf.workReportMaxTime),hex4CombineOne(taginf.idleReportMaxTime),hex4CombineOne(taginf.workReportMaxMeter),hex4CombineOne(taginf.idleReportMaxMeter));
					gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]ManageID [%02x,%02x,%02x,%02x,%02x,%02x]", __FUNCTION__, __LINE__,taginf.ManageID[0],taginf.ManageID[1],taginf.ManageID[2],taginf.ManageID[3],taginf.ManageID[4],taginf.ManageID[5]);
					gaoz_log_debug_printf(INFOR_MODE,"800b","[%s-%d]readTerminalPara success![%d,%d]", __FUNCTION__, __LINE__,hex4CombineOne(taginf.AuthCode),(taginf.AuthCodeFlag));
				}
			}
			port1 = 0;
			memset(host,0,sizeof(host));
			DecASCII2HexDWORD((uint8_t *)taginf.Port1,taginf.Port1Len,&port1);
			memcpy(host,taginf.IP1,taginf.IP1Len);
			if((host == 0) || (port1 == 0)) 
			{
				gaoz_task_sleep(5000); 
				continue;
			}
			gaoz_log_debug_printf(INFOR_MODE,"800b","socket host[%s]\n", host);
			gaoz_log_debug_printf(INFOR_MODE,"800b","socket port[%d]\n", port1);
			gaoz_log_debug_printf(INFOR_MODE,"800b","major_info->Mode [%x]\n", taginf.Mode);	
		#if 1/*2022.05.09 YXX 不需要等待，直接注册网络即可。底层网络没有成功时直接返回错误标志*/
			while(loopcnt < 10)
			{
				gaoz_power_man_wakeup_task_num_run();
				 gaoz_task_sleep(1000); 
				loopcnt++;
				gaoz_power_man_wakeup_task_num_stop();
			}
			loopcnt = 0;
		#endif
		}
		for(;;)
		{
			gaoz_mon_reset_task_dog();
			if( national808_net_create_st_check( &socket_handle_1 , &socket_state_1 , host, port1 ) != pdPASS )
			{
				gaoz_task_sleep(1000); /*等待网络稳定，重新进行网络连接*/
				if(national808_auth_recv_st  >= 5)
				{
					national808_net_runing_state_set( TER_RUNING_INIT );
					gaoz_system_wakeup_rtc_time_set(RTC_NET,hex4CombineOne(taginf.heartBeatDly)); 
					gaoz_task_sleep(30000); 
					gaoz_mon_reset_task_dog(); 
					gaoz_system_wakeup_rtc_time_set(RTC_NET,hex4CombineOne(taginf.heartBeatDly));
					gaoz_task_sleep(30000); 
					gaoz_mon_reset_task_dog(); 
					national808_auth_recv_st = 0;
					national808_net_runing_state_set( TER_RUNING_REG );
				}
			}
			else
			{
				if(net_rst == NET_RST_END)
				{
					net_rst = NET_RST_INT;
					saveserviceloadpara(NULL,2,NULL);//clear authcode
					socket_close(&socket_handle_1);
					socket_state_1.create_socket_state = SOCKET_LINK_CREATE_ERROR;
					break;
				}
				gaoz_task_sleep(100);  
			}
		}                  
	}
}

/** ****************************************************************************
* @remarks       void  national808_send_data_handle_task( void * param)
* @brief         处理808发送数据处理任务
* @param[in]     * param 任务参数
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void national808_send_data_handle_task(void *param)
{
    ( void ) param;
	
	gaoz_log_debug_printf(INFOR_MODE,"800b","TERMOTA %d,%s\r\n",terota_handle.upgrade_type,terota_handle.serveradr);
	gaoz_mon_reg_task_dog( 60 * GAOZ_TICK_PERIOD_S ,(uint8_t *)NAT808_SENDTASK_NAME ,TASK_SEM_YES);
	
	for( ;; )
    {
        gaoz_mon_reset_task_dog();
		/*为了解决系统休眠以后不能快速进入主程序进行数据处理，将网络休眠状态给屏蔽掉。YXX，2022.07.25*/
		if( (socket_state_1.create_socket_state != SOCKET_LINK_CREATE_OK ) )//|| (n808_netready != NET_READY_OK) )
		{
			gaoz_sys_state_state_set( SYS_REG, SYS_REG_NO );
			gaoz_sys_state_state_set( SYS_LAND, SYS_LAND_NO );
			gaoz_task_sleep( 100 );
			continue;
		}
        if( national808_data_manage_fun(&national808_send_data , &national808_response ) == pdPASS )
        {	
			if( national808_send_data == PLAT_SEND_OK )          /*发送数据成功*/
            {
                national808_net_data.send_st = 0;
                if( national808_response == PLAT_HAVE_RESPONSE ) /*等待平台应答*/
                {
                    if( national808_wait_response_result( NET_ACK_QUEUE_RX_DATA_TIME ) == pdPASS )
                    {   /* 网络数据接收成功 */
                        national808_net_data.recv_st = 0;
                    }
                    else
                    {   
						 /* 网络数据接收失败 */
						 gaoz_log_debug_printf(INFOR_MODE,"800b","national808 auth fail wait -- 0\n");
						if(national808_runing_st == TER_RUNING_AUTH)
						{
							gaoz_log_debug_printf(INFOR_MODE,"800b","national808 auth fail wait -- national808_auth_recv_st = %d\n",national808_auth_recv_st);
					    	national808_auth_recv_st++;             /*鉴权失败计数*/
						}
						/* 网络数据接收失败 */
                       national808_net_data.recv_st ++;         /*接收数据错误状态计数器*/
					   #if 0
					   if ( national808_net_runing_state_get() == TER_RUNING_DATA )
					   {
							national808_data_st.send_st = N808_SEND_WAIT;
					   }
					   if((national808_net_data.recv_st > 4) && 
					   		(national808_net_runing_state_get() == TER_RUNING_QUERY_PKEKEY))
					   {
							national808_net_data.recv_st = 0;
							national808_net_runing_state_set( TER_RUNING_DATA );   
					   }
					   #endif
					   gaoz_task_sleep(1000);					/*数据接收失败后等等1S中防止异常出现数据快速发送*/
                    }
                }
				gaoz_power_man_wakeup_task_num_stop();
            }
            else
            {
                national808_net_data.send_st ++;                /*发送数据错误状态计数器，延时1S中重新进行发送*/
				gaoz_task_sleep(1000);
            }
        }
		else
		{
			national808_plat_time_delay( 100 );               	/*使用消息邮箱检测平台主动下发的数据，增强信息处理的及时性*/
		}
    }
}

/** ****************************************************************************
* @remarks       static void  national_recv_data_handle_task( void * pvParameters)
* @brief         处理808接收数据任务
* @param[in]     * pvParameters 任务参数
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void  national808_recv_data_handle_task( void * pvParameters)
{ 
    ( void ) pvParameters;
	uint8_t *read_buf = NULL;
    uint16_t read_len = 0;
    socket_handle_s *handle = NULL;
	//socket_state_t *state = NULL;
	
	handle = &socket_handle_1;
	//state = &socket_state_1;
    read_buf = (uint8_t *)gaoz_fibo_malloc( NET_RECV_DATA_LEN + 8 );
    gaoz_mon_reg_task_dog( 60 * GAOZ_TICK_PERIOD_S ,(uint8_t * )NAT808_RECVTASK_NAME ,TASK_SEM_YES);
    for( ;; )
    {
        gaoz_mon_reset_task_dog();
        read_len = socket_recv( (socket_handle_s  *)handle, read_buf ,1000 );
        if( read_len > 0 ) 
        {
			gaoz_power_man_wakeup_task_num_run(); 
			parse_patio_recv_data(read_buf, read_len);
			gaoz_power_man_wakeup_task_num_stop();
        }
		national808_net_control_state_check();
    }
}

/** ****************************************************************************
* @remarks      uint16_t SendRegister(uint8_t *da)
* @brief         注册
* @param[in]     无
* @param[out]    *da缓存区
* @return        缓存区长度
* @attention     
*******************************************************************************/
static uint16_t SendRegister(uint8_t *da)
{
	uint8_t idx = 0;
	uint8_t term_id[4] = { 0 };
	uint8_t AuthDa[200] = { 0 };	
	uint16_t txLen = 0;
	uint8_t ccid[20]={0};

	//Message_ID
	idx = 0;
	memcpy(&AuthDa[idx], "\x01\x00",2);
	idx += 2;

	//Message_Property,afterward
	//memcpy(&AuthDa[idx], "\x00\x05",2);
	idx += 2;

	//Terminal_Num
	memcpy(&AuthDa[idx],taginf.ManageID, 6);
	idx += 6;

	//Message_Serial_Number
	AuthDa[idx++] = (uint8_t)(appserialNum >> 8);
	AuthDa[idx++] = (uint8_t)(appserialNum);
	appserialNum ++;
	if (appserialNum > 0x8000)
	{
		appserialNum = 1;
	}

	//省域ID

	//memcpy(&AuthDa[idx],Current_Info.ProvinceID, 2);
	memcpy(&AuthDa[idx],"61", 2);	//陕西
	//memset(&AuthDa[idx], 0, 2);
	idx += 2;
	//市县域ID
	//memcpy(&AuthDa[idx],Current_Info.TownID, 2);
	memset(&AuthDa[idx], '0', 2);
	idx += 2;

	//制造商ID
	memcpy(&AuthDa[idx], "GZCo.", 5);
	idx += 5;

	//终端型号
	memset((uint8_t *)&AuthDa[idx], 0x00, 20 );
	memcpy((uint8_t *)&AuthDa[idx], "HRC-001A", 8 );
	//memcpy(&AuthDa[idx], "car terminalRentE150", 20);	
	idx += 20;
	
	//终端ID
	memcpy(term_id,terminid /*"\x01\x00\x07\x28"*/, 4);
	memcpy(&AuthDa[idx], term_id, 4);
	idx += 4;
	memset(&AuthDa[idx], 0, 3);
	idx += 3;

	//车牌颜色
	AuthDa[idx++] = 0;

	//车辆标识
	//memset(&AuthDa[idx], 0x38, 17);
	//idx += 17;
	//20160428 要求改写的部分
	net_module_run_state_get( MOD_CCID, (uint8_t *)ccid);
	memcpy(&AuthDa[idx], ccid, 20);
	idx += 20;

	AuthDa[idx++] = 0;	//string的结尾
	

	//消息体属性
	txLen = idx + 1;
	if (txLen < 13)
	{
		txLen = 13;
	}
	AuthDa[2] = (uint8_t)((txLen - 13) >> 8);
	AuthDa[3] = (uint8_t)(txLen - 13);

	//校验
	AuthDa[idx] = get_chk_xor(AuthDa, idx);
	idx ++;

    return msgtranslation(AuthDa,da, idx);
}
/** ****************************************************************************
* @remarks      uint16_t Authentication(uint8_t *da)
* @brief         鉴权
* @param[in]    无 
* @param[out]   *da缓存区	
* @return        缓存区长度
* @attention     
*******************************************************************************/
static uint16_t Authentication(uint8_t *da)
{
	uint8_t idx = 0;
	uint8_t term_id[4] = { 0 };
	uint8_t AuthDa[220] = { 0 };	
	uint8_t tmpDa[10] = { 0 };
	uint8_t reDa = 0;
	uint8_t ccid[20] = { 0 };
	n808_vehicle_data_t data_vehicle;
	char btmac[30] = { 0 };
	uint8_t btmac_hex[6]={0};
	uint8_t vin[17];
	uint8_t	auth_reason = 0;

	vehicle_data_now_get(&data_vehicle);
	//车辆管理ID
	memcpy(term_id, terminid/*"\x01\x00\x07\x28"*/, 4);

	//Message_ID
	idx = 0;
	memcpy(&AuthDa[idx], "\x05\x01",2);
	idx += 2;

	//Message_Property, 放在最后
	//memcpy(&AuthDa[idx], "\x00\x1D",2);
	idx += 2;

	//Terminal_Num
	memcpy(&AuthDa[idx],taginf.ManageID, 6);
	idx += 6;

	//Message_Serial_Number
	AuthDa[idx++] = (uint8_t)(appserialNum >> 8);
	AuthDa[idx++] = (uint8_t)(appserialNum);
    appserialNum ++;
	if (appserialNum > 0x8000)
	{
		appserialNum = 1;
	}

	//Manage_ID  鉴权码
	memcpy(&AuthDa[idx],taginf.AuthCode, 4);
	idx += 4;

	//Term_ID 设备ID
	memcpy(&AuthDa[idx],term_id, 4);
	idx += 4;

	//科目编号  保留
	AuthDa[idx++] = ( uint8_t )( vehicle_type_data_get() << 7 );
	
	net_module_run_state_get( MOD_CCID, (uint8_t *)ccid);
	memcpy(&AuthDa[idx], ccid, 20);
	idx += 20;
	
	//当前版本号长度
	
	//放入当前软件版本号9字节
	AuthDa[idx++] = S_VER_LEN;
	if (S_VER_LEN <= 9)
	{
		memcpy(&AuthDa[idx], get_mcuversion(), S_VER_LEN);
		idx += S_VER_LEN;
	}
	
	//正在升级版本号长度，如果=0，则没有正在升级的版本号
	reDa = 0;//reCurUpData(tmpDa, 0);
	if (reDa == 0)
	{
		AuthDa[idx++] = 0;
	}
	else
	{
		AuthDa[idx++] = reDa;
		memcpy(&AuthDa[idx], tmpDa, reDa);
		idx += reDa;
	}
	
	//OBD升级的版本号
	AuthDa[idx++] = 5+12;
	memset(&AuthDa[idx], 0, 17);
	idx += 5 + 12;
	
	reDa = 0;//reCurUpData(tmpDa, 0xBD);
	if (reDa == 0)
	{
		AuthDa[idx++] = 0;
	}
	else
	{
		AuthDa[idx++] = reDa;
		memcpy(&AuthDa[idx], tmpDa, reDa);
		idx += reDa;
	}
	//追加包类型+长度+内容
	AuthDa[idx++] = 0x01;//VIN 
	memset(vin,0,17);

	if(vehicle_vin_get(vin) == pdPASS) 
	{
		AuthDa[idx++] = 0x11;//VIN
		memcpy(&AuthDa[idx],vin,17);
		idx += 17; 
	}	 
	else
	{
		AuthDa[idx++] = 0;
	} 
 
	AuthDa[idx++] = 0x02;//BLE MAC
	#if 1
	AuthDa[idx++] = 0x06;//
	reDa = ble_drive_macaddr_read(btmac);///保留
	gaoz_log_debug_printf(INFOR_MODE,"800b","ble_drive_macaddr_read : %s,%d\r\n",btmac,reDa);
	ASCIImac2Hex((uint8_t *)btmac,strlen(btmac),btmac_hex);
	AuthDa[idx++] = btmac_hex[5];//
	AuthDa[idx++] = btmac_hex[4];//
	AuthDa[idx++] = btmac_hex[3];//
	AuthDa[idx++] = btmac_hex[2];//
	AuthDa[idx++] = btmac_hex[1];//
	AuthDa[idx++] = btmac_hex[0];//
	#else
		AuthDa[idx++] = 0;
	#endif
	AuthDa[idx++] = 0x03;//固件
	{
	INT8 message[256] = {0};
	sprintf(message, "%s", fibo_get_sw_verno());
	gaoz_log_debug_printf(INFOR_MODE,"800b", "fibo_get_sw_verno[%s]]", message);
	AuthDa[idx++] = strlen(message);//length
	memcpy(&AuthDa[idx], message, strlen(message));
	idx += strlen(message);
	}
	AuthDa[idx++] = 0x04;//APP
	AuthDa[idx++] = strlen(gz_sw_verno);//length
	memcpy(&AuthDa[idx], gz_sw_verno, strlen(gz_sw_verno));
	idx += strlen(gz_sw_verno);

	//MCU配置表版本05

	AuthDa[idx++] = 0x06;//硬件类型
	AuthDa[idx++] = strlen(GAOZ_HW_TYPE1);//length
	memcpy(&AuthDa[idx], GAOZ_HW_TYPE1, strlen(GAOZ_HW_TYPE1));
	idx += strlen(GAOZ_HW_TYPE1);
 
	// 鉴权 重启原因
	AuthDa[idx++] = 0x0c;
	AuthDa[idx++] = 0x02;
	auth_reason = national808_auth_reason_get();//鉴权原因 
	AuthDa[idx++] = auth_reason;
	AuthDa[idx++] = national808_reset_reason;//重启原因
	 
	gaoz_log_debug_printf(INFOR_MODE,"800b", "national808 auth info auth reason[%d] reset reason[%d]\r\n",auth_reason, national808_reset_reason);

	
	AuthDa[2] = (uint8_t)((idx - 12) >> 8);
	AuthDa[3] = (uint8_t)(idx - 12);

	//校验
	AuthDa[idx] = get_chk_xor(AuthDa, idx);
	idx ++;

    return msgtranslation(AuthDa,da, idx);
}
 

/** ****************************************************************************
* @remarks      uint16_t SendHeart(uint8_t *da)
* @brief         心跳
* @param[in]     无
* @param[out]    *da缓存区
* @return       缓存区长度
* @attention     
*******************************************************************************/
static uint16_t SendHeart(uint8_t *da)
{
	uint8_t idx;
	uint8_t AuthDa[200];	
	uint16_t txLen;


	//Message_ID
	idx = 0;
	memcpy(&AuthDa[idx], "\x05\x06",2);
	idx += 2;

	//Message_Property,afterward
	//memcpy(&AuthDa[idx], "\x00\x05",2);
	idx += 2;

	//Terminal_Num
	memcpy(&AuthDa[idx],taginf.ManageID, 6);
	idx += 6;

	//Message_Serial_Number
	AuthDa[idx++] = (uint8_t)(appserialNum >> 8);
	AuthDa[idx++] = (uint8_t)(appserialNum);
	appserialNum ++;
	if (appserialNum > 0x8000)
	{
		appserialNum = 1;
	}

	//消息体属性
	txLen = idx + 1;
	if (txLen < 13)
	{
		txLen = 13;
	}
	AuthDa[2] = (uint8_t)((txLen - 13) >> 8);
	AuthDa[3] = (uint8_t)(txLen - 13);

	//校验
	AuthDa[idx] = get_chk_xor(AuthDa, idx);
	idx ++;

    return msgtranslation(AuthDa,da, idx);
}
/** ****************************************************************************
* @remarks      uint16_t querypkekey(uint8_t *da)
* @brief         请求钥匙
* @param[in]     无
* @param[out]    *da缓存区
* @return       缓存区长度
* @attention     
*******************************************************************************/
static uint16_t querypkekey(uint8_t *da)
{
	uint8_t idx;
	uint8_t AuthDa[300];	
	uint16_t txLen;

	//Message_ID
	idx = 0;
	memcpy(&AuthDa[idx], "\x06\x01",2);
	idx += 2;

	//Message_Property,afterward
	//memcpy(&AuthDa[idx], "\x00\x05",2);
	idx += 2;

	//Terminal_Num
	memcpy(&AuthDa[idx],taginf.ManageID, 6);
	idx += 6;

	//Message_Serial_Number
	AuthDa[idx++] = (uint8_t)(appserialNum >> 8);
	AuthDa[idx++] = (uint8_t)(appserialNum);
	appserialNum ++;
	if (appserialNum > 0x8000)
	{
		appserialNum = 1;
	}

	//消息体属性
	txLen = idx + 1;
	if (txLen < 13)
	{
		txLen = 13;
	}
	AuthDa[2] = (uint8_t)((txLen - 13) >> 8);
	AuthDa[3] = (uint8_t)(txLen - 13);

	//校验
	AuthDa[idx] = get_chk_xor(AuthDa, idx);
	idx ++;

    return msgtranslation(AuthDa,da, idx);
}


/** ****************************************************************************
* @remarks       static uint16_t network_data_transmission( uint8_t *da )
* @brief         网络数据透传
* @param[in]     无
* @param[out]    *da缓存区
* @return        缓存区长度
* @attention     
*******************************************************************************/
static uint16_t network_data_transmission( uint8_t *da )
{
	uint8_t tmpDa[500] = { 0 };
	uint16_t index = 0;
	uint8_t led_size = 0;
	uint8_t led_data[VEH_WAEMCAR_LED_RET_LEN] = { 0 };
	//消息头，共用部分		
	tmpDa[index++] = 0x06;
	tmpDa[index++] = 0x12;
	
	//car ID
	index = 4;
	memcpy(&tmpDa[index], taginf.ManageID, 6);
	index += 6;
	//流水号
	tmpDa[index++] = (uint8_t)(appserialNum >> 8);
	tmpDa[index++] = (uint8_t)(appserialNum & 0xff);
	appserialNum++;
	if (appserialNum > 0x8000)
	{
		appserialNum = 1;
	}
	/*读取LED数据*/
	led_size = warmcarled_data_read( led_data );
	//消息头，共用部分		
	tmpDa[index++] = 0;
	tmpDa[index++] = led_size;
	if( led_size != 0 )
	{
		memcpy(&tmpDa[index], led_data, led_size );
		index += led_size;
	}
	//属性
	tmpDa[2] = (uint8_t)((index - 12) >> 8);
	tmpDa[3] = (uint8_t)(index - 12);
	//校验
	tmpDa[index] = get_chk_xor(tmpDa,index);
	index++;
	
    return msgtranslation(tmpDa,da,index);
}

/** ****************************************************************************
* @remarks       static uint16_t network_data_engine_start_transmission( uint8_t *da )
* @brief         一键启动应答数据上传
* @param[in]     无
* @param[out]    *da缓存区
* @return        缓存区长度
* @attention     
*******************************************************************************/
static uint16_t network_data_engine_start_transmission( uint8_t *da )
{
	uint8_t tmpDa[500] = { 0 };
	uint16_t index = 0;
	uint8_t engine_size = 0;
	uint8_t engine_data[ sizeof(vehicle_engine_start_result_t) ] = { 0 };
	//消息头，共用部分		
	tmpDa[index++] = 0x05;
	tmpDa[index++] = 0x95;
	
	//car ID
	index = 4;
	memcpy(&tmpDa[index], taginf.ManageID, 6);
	index += 6;
	//流水号
	tmpDa[index++] = (uint8_t)(appserialNum >> 8);
	tmpDa[index++] = (uint8_t)(appserialNum & 0xff);
	appserialNum++;
	if (appserialNum > 0x8000)
	{
		appserialNum = 1;
	}
	/*读取ENGINA数据*/
	engine_size = vehicle_engine_start_result_get( engine_data );
	if( engine_size != 0 )
	{
		memcpy(&tmpDa[index], engine_data, engine_size );
		index += engine_size;
	}
	//属性
	tmpDa[2] = (uint8_t)((index - 12) >> 8);
	tmpDa[3] = (uint8_t)(index - 12);
	//校验
	tmpDa[index] = get_chk_xor(tmpDa,index);
	index++;
	
    return msgtranslation(tmpDa,da,index);
}

/** ****************************************************************************
* @remarks       static uint16_t network_data_fault_code_transmission( uint8_t *da )
* @brief         故障码应答数据上传
* @param[in]     无
* @param[out]    *da缓存区
* @return        缓存区长度
* @attention     
*******************************************************************************/
static uint16_t network_data_fault_code_transmission( uint8_t *da )
{
	uint8_t tmpDa[500] = { 0 };
	uint16_t index = 0;
	uint8_t code_size = 0;
	uint8_t code_data[256] = { 0 };
	rtc_struct location_Time;
	//消息头，共用部分		
	tmpDa[index++] = 0x01;
	tmpDa[index++] = 0x02;
	//car ID
	index = 4;
	memcpy(&tmpDa[index], taginf.ManageID, 6);
	index += 6;
	//流水号
	tmpDa[index++] = (uint8_t)(appserialNum >> 8);
	tmpDa[index++] = (uint8_t)(appserialNum & 0xff);
	appserialNum++;
	if (appserialNum > 0x8000)
	{
		appserialNum = 1;
	}
	/*读取设备当前时间*/
	gaoz_rtc_sys_get(RTC_TIM_CAL_BCD,&location_Time);
	tmpDa[index++] = ( uint8_t )(location_Time.year&0xff);
	tmpDa[index++] = location_Time.month;
	tmpDa[index++] = location_Time.day;
	tmpDa[index++] = location_Time.hour;
	tmpDa[index++] = location_Time.minute;
	tmpDa[index++] = location_Time.second;
	/*读取故障码信息数据*/
	code_size = vehicle_fault_code_infor_get( code_data );
	if( code_size != 0 )
	{
		memcpy(&tmpDa[index], code_data, code_size );
		index += code_size;
	}
	//属性
	tmpDa[2] = (uint8_t)((index - 12) >> 8);
	tmpDa[3] = (uint8_t)(index - 12);
	//校验
	tmpDa[index] = get_chk_xor(tmpDa,index);
	index++;
	
    return msgtranslation(tmpDa,da,index);
}


/** ****************************************************************************
* @remarks        uint16_t network_data_vehicle_fault_code_transmission( uint8_t *da )
* @brief         故障码应答数据上传
* @param[in]     无
* @param[out]    *da缓存区
* @return        缓存区长度
* @attention     
*******************************************************************************/
 uint16_t network_data_vehicle_fault_code_transmission( uint8_t *da )
{
	uint8_t tmpDa[1024] = { 0 };
	uint16_t index = 0;
	uint16_t code_size = 0;
	uint8_t code_data[1024] = { 0 };
	rtc_struct location_Time;
	//消息头，共用部分		
	tmpDa[index++] = 0x01;
	tmpDa[index++] = 0x04;
	//car ID
	index = 4;
	memcpy(&tmpDa[index], taginf.ManageID, 6);
	index += 6;
	//流水号
	tmpDa[index++] = (uint8_t)(appserialNum >> 8);
	tmpDa[index++] = (uint8_t)(appserialNum & 0xff);
	appserialNum++;
	if (appserialNum > 0x8000)
	{
		appserialNum = 1;
	}
	/*读取设备当前时间*/
	gaoz_rtc_sys_get(RTC_TIM_CAL_BCD,&location_Time);
	tmpDa[index++] = ( uint8_t )(location_Time.year&0xff);
	tmpDa[index++] = location_Time.month;
	tmpDa[index++] = location_Time.day;
	tmpDa[index++] = location_Time.hour;
	tmpDa[index++] = location_Time.minute;
	tmpDa[index++] = location_Time.second;
	/*读取故障码信息数据*/
	code_size = vehicle_dtc_code_get( code_data );
	if( code_size != 0 )
	{
		memcpy(&tmpDa[index], code_data, code_size );
		index += code_size;
	}
	//属性
	tmpDa[2] = (uint8_t)((index - 12) >> 8);
	tmpDa[3] = (uint8_t)(index - 12);
	//校验
	tmpDa[index] = get_chk_xor(tmpDa,index);
	index++;
	gaoz_log_debug_printf(INFOR_MODE,"800b","mcu debug code_size: %d index:%d\r\n",code_size,index);
    return msgtranslation(tmpDa,da,index);
}

/** ****************************************************************************
* @remarks       static uint16_t network_data_maintenance_infor_transmission( uint8_t *da )
* @brief         保养信息上报
* @param[in]     无
* @param[out]    *da缓存区
* @return        缓存区长度
* @attention     
*******************************************************************************/
static uint16_t network_data_maintenance_infor_transmission( uint8_t *da )
{
	uint8_t tmpDa[500] = { 0 };
	uint16_t index = 0;
	uint8_t main_size = 0;
	uint8_t main_data[ sizeof(vehicle_maintenance_infor_t) ] = { 0 };
	rtc_struct location_Time;
	//消息头，共用部分		
	tmpDa[index++] = 0x01;
	tmpDa[index++] = 0x03;
	//car ID
	index = 4;
	memcpy(&tmpDa[index], taginf.ManageID, 6);
	index += 6;
	//流水号
	tmpDa[index++] = (uint8_t)(appserialNum >> 8);
	tmpDa[index++] = (uint8_t)(appserialNum & 0xff);
	appserialNum++;
	if (appserialNum > 0x8000)
	{
		appserialNum = 1;
	}
	/*读取BCD时间数据*/
	gaoz_rtc_sys_get(RTC_TIM_CAL_BCD,&location_Time);
	tmpDa[index++] = ( uint8_t )(location_Time.year&0xff);
	tmpDa[index++] = location_Time.month;
	tmpDa[index++] = location_Time.day;
	tmpDa[index++] = location_Time.hour;
	tmpDa[index++] = location_Time.minute;
	tmpDa[index++] = location_Time.second;
	/*读取保养信息数据*/
	main_size = vehicle_maintenance_cfg_get( main_data );
	if( main_size != 0 )
	{
		memcpy(&tmpDa[index], main_data, main_size );
		index += main_size;
	}
	//属性
	tmpDa[2] = (uint8_t)((index - 12) >> 8);
	tmpDa[3] = (uint8_t)(index - 12);
	//校验
	tmpDa[index] = get_chk_xor(tmpDa,index);
	index++;
	
    return msgtranslation(tmpDa,da,index);
}

/** ****************************************************************************
* @remarks       static uint16_t network_data_bms_infor_transmission( uint8_t *da )
* @brief         BMS数据包信息上传
* @param[in]     无
* @param[out]    *da缓存区
* @return        缓存区长度
* @attention     
*******************************************************************************/
static uint16_t network_data_bms_infor_transmission( uint8_t *da )
{
	uint8_t tmpDa[500] = { 0 };
	uint16_t index = 0;
	uint8_t bms_size = 0;
	uint8_t bms_data[ sizeof(vehicle_bms_infor_t) ] = { 0 };
	//消息头，共用部分
	tmpDa[index++] = 0x06;
	tmpDa[index++] = 0x30;
	//car ID
	index = 4;
	memcpy(&tmpDa[index], taginf.ManageID, 6);
	index += 6;
	//流水号
	tmpDa[index++] = (uint8_t)(appserialNum >> 8);
	tmpDa[index++] = (uint8_t)(appserialNum & 0xff);
	
	/*读取BMS数据*/
	bms_size = vehicle_bms_infor_get( bms_data );
	if( bms_size != 0 )
	{
		memcpy(&tmpDa[index], bms_data, bms_size );
		index += bms_size;
	}
	else
	{
		return 0;
	}
	/*当数据有效时对流水号加一处理*/
	appserialNum++;
	if (appserialNum > 0x8000)
	{
		appserialNum = 1;
	}
	//属性
	tmpDa[2] = (uint8_t)((index - 12) >> 8);
	tmpDa[3] = (uint8_t)(index - 12);
	//校验
	tmpDa[index] = get_chk_xor(tmpDa,index);
	index++;
	
    return msgtranslation(tmpDa,da,index);
}

/** ****************************************************************************
* @remarks       static uint16_t network_data_seed_infor_transmission( uint8_t *da )
* @brief         SEED数据包信息上传
* @param[in]     无
* @param[out]    *da缓存区
* @return        缓存区长度
* @attention     
*******************************************************************************/
static uint16_t network_data_seed_infor_transmission( uint8_t *da )
{
	uint8_t tmpDa[500] = { 0 };
	uint16_t index = 0;
	uint8_t seed_size = 0;
	uint8_t seed_data[ sizeof(vehicle_seed_infor_t) ] = { 0 };
	//消息头，共用部分
	tmpDa[index++] = 0x06;
	tmpDa[index++] = 0x54;
	//car ID
	index = 4;
	memcpy(&tmpDa[index], taginf.ManageID, 6);
	index += 6;
	//流水号
	tmpDa[index++] = (uint8_t)(appserialNum >> 8);
	tmpDa[index++] = (uint8_t)(appserialNum & 0xff);
	appserialNum++;
	if (appserialNum > 0x8000)
	{
		appserialNum = 1;
	}
	/*读取BMS数据*/
	seed_size = vehicle_seed_infor_get( seed_data );
	if( seed_size != 0 )
	{
		memcpy(&tmpDa[index], seed_data, seed_size );
		index += seed_size;
	}
	else
	{
		return 0;
	}
	//属性
	tmpDa[2] = (uint8_t)((index - 12) >> 8);
	tmpDa[3] = (uint8_t)(index - 12);
	//校验
	tmpDa[index] = get_chk_xor(tmpDa,index);
	index++;
	
    return msgtranslation(tmpDa,da,index);
}

/** ****************************************************************************
* @remarks       static uint16_t network_data_adas_infor_transmission( uint8_t *da )
* @brief         ADAS数据包信息上传
* @param[in]     无
* @param[out]    *da缓存区
* @return        缓存区长度
* @attention     
*******************************************************************************/
static uint16_t network_data_adas_infor_transmission( uint8_t *da )
{
	uint8_t tmpDa[1224] = { 0 };
	uint16_t index = 0;
	uint16_t adas_size = 0;
	// uint8_t adas_data[ sizeof(vehicle_seed_infor_t) ] = { 0 };
	uint8_t adas_data[ 1110] = { 0 };
	//消息头，共用部分
	tmpDa[index++] = 0x06;
	tmpDa[index++] = 0x55;
	//car ID
	index = 4;
	memcpy(&tmpDa[index], taginf.ManageID, 6);
	index += 6;
	//流水号
	tmpDa[index++] = (uint8_t)(appserialNum >> 8);
	tmpDa[index++] = (uint8_t)(appserialNum & 0xff);
	appserialNum++;
	if (appserialNum > 0x8000)
	{
		appserialNum = 1;
	}
	/*读取BMS数据*/
	adas_size = vehicle_adas_infor_get( adas_data );
	if( adas_size != 0 )
	{	
		gaoz_log_debug_printf(INFOR_MODE,"800b","800b debug tmpDa[0] = %d tmpDa[1]=%d  adas_size:%d  sizeof(vehicle_seed_infor_t):%d \r\n",tmpDa[0],tmpDa[1],adas_size,sizeof(vehicle_seed_infor_t));
		memcpy(&tmpDa[index], adas_data, adas_size );
		gaoz_log_debug_printf(INFOR_MODE,"800b","800b debug tmpDa[0] = %d tmpDa[1]=%d  adas_size:%d  sizeof(vehicle_seed_infor_t):%d \r\n",tmpDa[0],tmpDa[1],adas_size,sizeof(vehicle_seed_infor_t));
		
		index += adas_size;
	}
	else
	{
		return 0;
	}
	//属性
	tmpDa[2] = (uint8_t)((index - 12) >> 8);
	tmpDa[3] = (uint8_t)(index - 12);
	//校验
	tmpDa[index] = get_chk_xor(tmpDa,index);
	index++;
	
    return msgtranslation(tmpDa,da,index);
}

/*
static uint16_t requestrsa(uint8_t *da)
{
	uint8_t idx;
	uint8_t AuthDa[100];	
	uint16_t txLen;


	//Message_ID
	idx = 0;
	memcpy(&AuthDa[idx], "\x05\x80",2);
	idx += 2;

	//Message_Property,afterward
	//memcpy(&AuthDa[idx], "\x00\x05",2);
	idx += 2;

	//Terminal_Num
	memcpy(&AuthDa[idx],taginf.ManageID, 6);
	idx += 6;

	//Message_Serial_Number
	AuthDa[idx++] = (uint8_t)(appserialNum >> 8);
	AuthDa[idx++] = (uint8_t)(appserialNum);
	appserialNum ++;
	if (appserialNum > 0x8000)
	{
		appserialNum = 1;
	}

	//消息体属性
	txLen = idx + 1;
	if (txLen < 13)
	{
		txLen = 13;
	}
	AuthDa[2] = (uint8_t)((txLen - 13) >> 8);
	AuthDa[3] = (uint8_t)(txLen - 13);

	//校验
	AuthDa[idx] = get_chk_xor(AuthDa, idx);
	idx ++;

    return msgtranslation(AuthDa,da, idx);
}*/
/** ****************************************************************************
* @remarks      uint16_t unregisterfromsys(uint8_t *da)
* @brief         终端注销
* @param[in]     无
* @param[out]    *da缓存区
* @return        缓存区长度
* @attention     
*******************************************************************************/
/*
static uint16_t unregisterfromsys(uint8_t *da)
{
	uint8_t idx;
	uint8_t AuthDa[100];	
	uint16_t txLen;


	//Message_ID
	idx = 0;
	memcpy(&AuthDa[idx], "\x00\x03",2);
	idx += 2;

	//Message_Property,afterward
	//memcpy(&AuthDa[idx], "\x00\x05",2);
	idx += 2;

	//Terminal_Num
	memcpy(&AuthDa[idx],taginf.ManageID, 6);
	idx += 6;

	//Message_Serial_Number
	AuthDa[idx++] = (uint8_t)(appserialNum >> 8);
	AuthDa[idx++] = (uint8_t)(appserialNum);
	appserialNum ++;
	if (appserialNum > 0x8000)
	{
		appserialNum = 1;
	}

	//消息体属性
	txLen = idx + 1;
	if (txLen < 13)
	{
		txLen = 13;
	}
	AuthDa[2] = (uint8_t)((txLen - 13) >> 8);
	AuthDa[3] = (uint8_t)(txLen - 13);

	//校验
	AuthDa[idx] = get_chk_xor(AuthDa, idx);
	idx ++;

    return msgtranslation(AuthDa,da, idx);
}
*/
/** ****************************************************************************
* @remarks      void get_majorterm_para(uint8_t *da, uint16_t *cnt)
* @brief         获取上报参数表内容
* @param[in]     无
* @param[out]    *da缓存区，*cnt长度
* @return        无
* @attention     
*******************************************************************************/
static void get_majorterm_para(uint8_t *da, uint16_t *cnt)
{
	uint8_t tempDa[10];
	uint8_t tempSt[20];
	uint16_t Tx_Len;

	//终端ID
	memcpy(tempDa,terminid, 4);
	Tx_Len = 0;
	memcpy(&da[Tx_Len], tempDa, 4);
	Tx_Len += 4;
	memcpy(&da[Tx_Len], "\x0\x0\x0", 3);
	Tx_Len += 3;
	//心跳间隔
	memcpy(&da[Tx_Len], taginf.heartBeatDly, 4);
	Tx_Len += 4;
	//主IP
	#if 0
	if(taginf.IP1Len < 15)
	{
		memcpy(&da[Tx_Len], taginf.IP1, taginf.IP1Len);
		Tx_Len += taginf.IP1Len;
		memset(tempSt,0,20);
		memcpy(&da[Tx_Len], tempSt, (15-taginf.IP1Len));
		Tx_Len += (15-taginf.IP1Len);
	}	
	else
	#endif
	da[Tx_Len++] = taginf.IP1Len;//
	{
		if(taginf.IP1Len != 0)
		{
			memcpy(&da[Tx_Len], taginf.IP1, taginf.IP1Len);
		}
		Tx_Len += taginf.IP1Len;
	}
	//副IP
	#if 0
	if(taginf.IP2Len < 15)
	{
		memcpy(&da[Tx_Len], taginf.IP2, taginf.IP2Len);
		Tx_Len += taginf.IP2Len;
		memset(tempSt,0,20);
		memcpy(&da[Tx_Len], tempSt, (15-taginf.IP2Len));
		Tx_Len += (15-taginf.IP2Len);	
	}
	else
	#endif
	da[Tx_Len++] = taginf.IP2Len;//
	{	
		if(taginf.IP2Len != 0)
		{
			memcpy(&da[Tx_Len], taginf.IP2, taginf.IP2Len);
		}
		Tx_Len += taginf.IP2Len;
	}
	//主端口号
	if(taginf.Port1Len < 5)
	{
		memcpy(&da[Tx_Len], taginf.Port1, taginf.Port1Len);
		Tx_Len += taginf.Port1Len;
		memset(tempSt,0,20);
		memcpy(&da[Tx_Len], tempSt, (5-taginf.Port1Len));
		Tx_Len += (5-taginf.Port1Len);
	}
	else
	{
		memcpy(&da[Tx_Len], taginf.Port1, taginf.Port1Len);
		Tx_Len += taginf.Port1Len;
	}

	//副端口号
	if(taginf.Port2Len < 5)
	{
		memcpy(&da[Tx_Len], taginf.Port2, taginf.Port2Len);
		Tx_Len += taginf.Port2Len;
		memset(tempSt,0,20);
		memcpy(&da[Tx_Len], tempSt, (5-taginf.Port2Len));
		Tx_Len += (5-taginf.Port2Len);
	}
	else
	{
		memcpy(&da[Tx_Len], taginf.Port2, taginf.Port2Len);
		Tx_Len += taginf.Port2Len;
	}

	//休眠时间上报间隔
	memcpy(&da[Tx_Len], taginf.idleReportMaxTime, 4);
	Tx_Len += 4;
	//正常时间上报间隔
	memcpy(&da[Tx_Len], taginf.workReportMaxTime, 4);
	Tx_Len += 4;
	//正常距离上报间隔
	memcpy(&da[Tx_Len], taginf.workReportMaxMeter, 4);
	Tx_Len += 4;
	//休眠距离上报间隔
	memcpy(&da[Tx_Len], taginf.idleReportMaxMeter, 4);
	Tx_Len += 4;
	
	//APN接入点名称
	if(taginf.APNLen < 15)
	{
		memcpy(&da[Tx_Len], taginf.APN, taginf.APNLen);
		Tx_Len += taginf.APNLen;
		memset(tempSt,0,20);
		memcpy(&da[Tx_Len], tempSt, (15-taginf.APNLen));
		Tx_Len += (15-taginf.APNLen);			
	}	
	else
	{
		memcpy(&da[Tx_Len], taginf.APN, taginf.APNLen);
		Tx_Len += taginf.APNLen;
	}
	//APN用户名称
	if(taginf.USERLen < 15)
	{
		memcpy(&da[Tx_Len], taginf.USER, taginf.USERLen);
		Tx_Len += taginf.USERLen;
		memset(tempSt,0,20);
		memcpy(&da[Tx_Len], tempSt, (15-taginf.USERLen));
		Tx_Len += (15-taginf.USERLen);			
	}
	else
	{
		memcpy(&da[Tx_Len], taginf.USER, taginf.USERLen);
		Tx_Len += taginf.USERLen;
	}
	//APN密码
	if(taginf.PWDLen < 15)
	{
		memcpy(&da[Tx_Len], taginf.PWD, taginf.PWDLen);
		Tx_Len += taginf.PWDLen;
		memset(tempSt,0,20);
		memcpy(&da[Tx_Len], tempSt, (15-taginf.PWDLen));
		Tx_Len += (15-taginf.PWDLen);
	}
	else
	{
		memcpy(&da[Tx_Len], taginf.PWD, taginf.PWDLen);
		Tx_Len += taginf.PWDLen;
	}
	//battime-on
	memcpy(&da[Tx_Len], tempSt, 4);
	Tx_Len += 4;
	//battime-off
	memcpy(&da[Tx_Len], tempSt, 4);
	Tx_Len += 4;
	//DNS
	da[Tx_Len++] = terinf.IP1Len;//
	if(terinf.IP1Len != 0)
	{
		memcpy(&da[Tx_Len], terinf.IP1, terinf.IP1Len);
		Tx_Len += terinf.IP1Len;
	}
	//DNS-port
	if(terinf.Port1Len < 5)
	{
		memcpy(&da[Tx_Len], terinf.Port1, terinf.Port1Len);
		Tx_Len += terinf.Port1Len;
		memset(tempSt,0,20);
		memcpy(&da[Tx_Len], tempSt, (5-terinf.Port1Len));
		Tx_Len += (5-terinf.Port1Len);
	}
	else
	{
		memcpy(&da[Tx_Len], terinf.Port1, terinf.Port1Len);
		Tx_Len += terinf.Port1Len;
	}
	//net-switch
	da[Tx_Len] = taginf.Mode|terinf.Mode;
	Tx_Len += 1;

	memset(tempSt,0,12);
	memcpy(&da[Tx_Len], tempSt, 12);
	Tx_Len += 12;
	
	*cnt = Tx_Len;
}
/*
static uint16_t rsasecret(uint8_t *da)
{
	uint8_t idx;
	uint8_t AuthDa[512];	
	uint16_t txLen;
	uint8_t respda[256]={0};
	//uint16_t ter_cnt;
	int ret = 0;

	//Message_ID
	idx = 0;
	memcpy(&AuthDa[idx], "\x05\x81",2);
	idx += 2;

	idx += 2;
	//Terminal_Num
	memcpy(&AuthDa[idx],taginf.ManageID, 6);
	idx += 6;

	//Message_Serial_Number
	AuthDa[idx++] = (uint8_t)(appserialNum >> 8);
	AuthDa[idx++] = (uint8_t)(appserialNum);
	appserialNum ++;
	if (appserialNum > 0x8000)
	{
		appserialNum = 1;
	}

	AuthDa[idx++] = (uint8_t)(0>>8);
	AuthDa[idx++] = (uint8_t)0;
	//应答ID
	AuthDa[idx++] = 0x95;
	AuthDa[idx++] = 0x81;
	
	ret = file_termpara_read(RSAPARA,(INT8 *)respda);
	if(ret < 0){
		#if 1
		gaoz_log_debug_printf(INFOR_MODE,"800b","filelog_init(RSAPARA)= %d", ret);
		#endif
	}else{
		#if 1
		gaoz_log_debug_printf(INFOR_MODE,"800b","filelog_init(RSAPARA)= %d", ret-1);
		#endif
		memcpy(&AuthDa[idx], respda, ret-1);
		idx += ret-1;
	}

	//消息体属性
	txLen = idx + 1;
	if (txLen < 13)
	{
		txLen = 13;
	}
	AuthDa[2] = (uint8_t)((txLen - 13) >> 8);
	AuthDa[3] = (uint8_t)(txLen - 13);

	//校验
	AuthDa[idx] = get_chk_xor(AuthDa, idx);
	idx ++;

    return msgtranslation(AuthDa,da, idx);
}
*/
/** ****************************************************************************
* @remarks      uint16_t parameter(uint8_t *da)
* @brief         终端参数表
* @param[in]     无
* @param[out]    *da缓存区
* @return        缓存区长度  
* @attention     
*******************************************************************************/
static uint16_t parameter(national808_net_devres_msg_t *res_msg, uint8_t *da)
{
	uint8_t idx;
	uint8_t AuthDa[512];	
	uint16_t txLen;
	uint8_t respda[512];
	uint16_t ter_cnt;

	//Message_ID
	idx = 0;
	memcpy(&AuthDa[idx], "\x05\x90",2);
	idx += 2;

	idx += 2;

	//Terminal_Num
	memcpy(&AuthDa[idx],taginf.ManageID, 6);
	idx += 6;

	//Message_Serial_Number
	AuthDa[idx++] = (uint8_t)(appserialNum >> 8);
	AuthDa[idx++] = (uint8_t)(appserialNum);
	appserialNum ++;
	if (appserialNum > 0x8000)
	{
		appserialNum = 1;
	}

	respda[0] = (uint8_t)(res_msg->respondsn>>8);
	respda[1] = (uint8_t)(res_msg->respondsn);
	//应答ID
	respda[2] = 0x95;
	respda[3] = 0x90;
	get_majorterm_para(&respda[4],&ter_cnt);//获取参数表
	memcpy(&AuthDa[idx], respda, ter_cnt+4);
	idx += ter_cnt+4;
	//消息体属性
	txLen = idx + 1;
	if (txLen < 13)
	{
		txLen = 13;
	}
	AuthDa[2] = (uint8_t)((txLen - 13) >> 8);
	AuthDa[3] = (uint8_t)(txLen - 13);

	//校验
	AuthDa[idx] = get_chk_xor(AuthDa, idx);
	idx ++;

    return msgtranslation(AuthDa,da, idx);
}
/** ****************************************************************************
* @remarks      uint16_t property(uint8_t *da)
* @brief         终端属性
* @param[in]     无
* @param[out]    *da缓存区
* @return        缓存区长度 
* @attention     
*******************************************************************************/
static uint16_t property(uint8_t *da)
{
	uint8_t idx;
	uint8_t AuthDa[128];	
	uint16_t txLen;
	uint8_t term_id[4];
	uint8_t ccid[20]={0};

	//Message_ID
	idx = 0;
	memcpy(&AuthDa[idx], "\x01\x07",2);
	idx += 2;

	idx += 2;

	//Terminal_Num
	memcpy(&AuthDa[idx],taginf.ManageID, 6);
	idx += 6;

	//Message_Serial_Number
	AuthDa[idx++] = (uint8_t)(appserialNum >> 8);
	AuthDa[idx++] = (uint8_t)(appserialNum);
	appserialNum ++;
	if (appserialNum > 0x8000)
	{
		appserialNum = 1;
	}
	//终端类型
	AuthDa[idx++] = 0;
	AuthDa[idx++] = (uint8_t)TERNIMAL_TYPE;
	
	//制造商ID
	memcpy(&AuthDa[idx], manufactureID, 5);
	idx += 5;

	//终端型号
	//memcpy(&AuthDa[19], terminal_type, 20);
	net_module_run_state_get( MOD_CCID, (uint8_t *)ccid);	
	memcpy(&AuthDa[idx], ccid, 20);	
	idx += 20;
	
	//终端ID
	memcpy(term_id,terminid, 4);
	memcpy(&AuthDa[idx], term_id, 4);
	idx += 4;
	memset(&AuthDa[idx], 0, 3);
	idx += 3;


	//终端SIM 卡ICCID，作废
	//Manage_ID  鉴权码
	memcpy(&AuthDa[idx], taginf.AuthCode, 4);
	idx += 4;
	//凑数
	memset(&AuthDa[idx], 0x31, 10-4);
	idx += 6;

	//终端硬件版本号长度
	AuthDa[idx++] = H_ver_len;

	//终端硬件版本号
	memcpy(&AuthDa[idx], H_ver, H_ver_len);

	idx += H_ver_len;

	//终端固件版本号长度
	AuthDa[idx++] = S_VER_LEN;
	//终端固件版本号
	//memcpy(&AuthDa[idx], S_VER, S_VER_LEN);
	if (S_VER_LEN <= 9)
	{
		memcpy(&AuthDa[idx], get_mcuversion(), S_VER_LEN);
		idx += S_VER_LEN;
	}
	//GNSS 模块属性
	AuthDa[idx++] = 0x03;

	//通信模块属性
	AuthDa[idx++] = 0x01;

	//增加OBD的版本号(固件)
	{
		INT8 message[256] = {0};
		sprintf(message, "%s", fibo_get_sw_verno());
		gaoz_log_debug_printf(INFOR_MODE,"800b", "fibo_get_sw_verno[%s]]", message);
		AuthDa[idx++] = strlen(message);//length
		memcpy(&AuthDa[idx], message, strlen(message));
		idx += strlen(message);
	}
	//app version
	AuthDa[idx++] = strlen(gz_sw_verno);//length
	memcpy(&AuthDa[idx], gz_sw_verno, strlen(gz_sw_verno));
	idx += strlen(gz_sw_verno);

	//消息体属性
	txLen = idx + 1;
	if (txLen < 13)
	{
		txLen = 13;
	}
	AuthDa[2] = (uint8_t)((txLen - 13) >> 8);
	AuthDa[3] = (uint8_t)(txLen - 13);

	//校验
	AuthDa[idx] = get_chk_xor(AuthDa, idx);
	idx ++;

    return msgtranslation(AuthDa,da, idx);
}



/** ****************************************************************************
* @remarks      uint16_t uploadposition(uint8_t *pDa)
* @brief        加载位置信息
* @param[in]     无
* @param[out]    *pDa缓存区
* @return       缓存区长度 
* @attention     
*******************************************************************************/
uint16_t uploadposition(uint8_t *pDa)
{
	uint8_t idx;
	uint8_t term_id[4];
	uint8_t AuthDa[500];	
    rtc_struct Location_Time;
	gnss_info_struct gnss_info;
	n808_vehicle_data_t data_vehicle;
	//gsen_bmi160_body_state_e gsen_st;
	uint8_t sys_power,veh_power,sys_bat,sys_rtc,sys_gps,sys_gprs,sys_gsen,/*sys_can,*/sys_flash,sys_ble,sys_sim,sys_vehicle_acc,sys_vehicle_ready;
	uint8_t auth_sta, sensor_st;

	vehicle_data_now_get(&data_vehicle);
	gaoz_gnss_info_now_get( &gnss_info );
	gaoz_rtc_sys_get(RTC_TIM_CAL_BCD,&Location_Time);
	//gsen_st = gsen_sensor_body_st_get();
	sys_power = sys_hard_state_get(SYS_POWER);
	sys_gsen = sys_hard_state_get(SYS_GSEN);
	sys_gps = sys_hard_state_get(SYS_GPS);
	veh_power = sys_hard_state_get(SYS_VEHICLE);
	sys_ble = sys_hard_state_get(SYS_BLE);
	sys_flash = sys_hard_state_get(SYS_FLASH);
	sys_bat = sys_hard_state_get(SYS_BAT);
	sys_rtc = sys_hard_state_get(SYS_RTC);
	sys_gprs = sys_hard_state_get(SYS_GPRS);
	//sys_can = sys_hard_state_get(SYS_CAN);
	sys_sim = sys_hard_state_get(SYS_SIM);
	sys_vehicle_acc = sys_hard_state_get(SYS_VEHICLE_ACC);
	sys_vehicle_ready = sys_hard_state_get(SYS_VEHICLE_READY);
	auth_sta = n808_authsta_get();
	sensor_st = vehicle_type_sensor_get();

	// if(gaoz_gnss_lbs_position_type_read()  == 0x04)
	// {
	// 	gnss_info.gnss_position_info.pos_flag = 1;
	// }
 
	//Message_ID
	idx = 0;
	//內容
	//alarm
	AuthDa[idx+3] = 0; //B0
	if(sys_gsen == SYS_GSEN_FAULE )
	{
		AuthDa[idx+3] |= 0x04;
	}
	else if(sys_gsen == SYS_GSEN_NORMAL)
	{
		AuthDa[idx+3] &= ~0x04;
	}
	
	if(sys_gps == SYS_GPS_NORMAL)
	{
		AuthDa[idx+3] &= ~0x10;
	}
	else if(sys_gps == SYS_GPS_FAULE)
	{
		AuthDa[idx+3] |= 0x10;
	}
	if(veh_power == VEH_POWER_UNDER)
	{
		AuthDa[idx+3] |= 0x80;
	}
	else if(veh_power == VEH_POWER_NORMAL)
	{
		AuthDa[idx+3] &= ~0x80;
	}
	AuthDa[idx+2] = 0; //B8
	if(sys_power == SYS_POWER_ON)
	{
		AuthDa[idx+2] &= ~0x01;
	}
	else if(sys_power == SYS_POWER_OFF)
	{
		AuthDa[idx+2] |= 0x01;
	}
	if(sys_ble == SYS_BLE_NORMAL)
	{
		AuthDa[idx+2] &= ~0x02;
	}
	else if(sys_ble == SYS_BLE_FAULE)
	{
		AuthDa[idx+2] |= 0x02;
	}
	if(sys_flash == SYS_FLASH_NORMAL)
	{
		AuthDa[idx+2] &= ~0x08;
	}
	else if(sys_flash == SYS_FLASH_FAULE)
	{
		AuthDa[idx+2] |= 0x08;
	}
	if(sys_bat == SYS_BAT_NORMAL)
	{
		AuthDa[idx+2] &= ~0x10;
	}
	else if(sys_bat == SYS_BAT_FAULE)
	{
		AuthDa[idx+2] |= 0x10;
	}

	if(sys_vehicle_acc == SYS_VEHICLE_STATE_ACC_NO_OFF)
	{
		AuthDa[idx+2] |= 0x20;
	}
	else if(sys_vehicle_ready == SYS_VEHICLE_STATE_ENG_START_NOT_RUN) 
	{
		AuthDa[idx+2] |= 0x40; 
	}
	else 
	{
		AuthDa[idx+2] &= ~0x60;	
	}

	AuthDa[idx+1] = 0;  //B16
	if( sensor_st == 0x01 )
	{
		AuthDa[idx+1] |= 0x01;
	}
	else
	{
		AuthDa[idx+1] &= ~0x01;
	}
	if(auth_sta == N808_AUTH_FAIL)
	{
		AuthDa[idx+1] |= 0x02;
	}
	else
	{
		AuthDa[idx+1] &= ~0x02;
	}
	
	if(sys_rtc == SYS_RTC_ERR)
	{
		AuthDa[idx+1] |= 0x10;
	}
	else if(sys_rtc == SYS_RTC_OK)
	{
		AuthDa[idx+1] &= ~0x10;
	}
	if(sys_gprs == SYS_GPRS_FAULE)
	{
		AuthDa[idx+1] |= 0x20;
	}
	else if(sys_gprs == SYS_GPRS_NORMAL)
	{
		AuthDa[idx+1] &= ~0x20;
	}
	if((n808_gsen_sensor_state_get()&0x04) == 0x04) //震动
	{
		AuthDa[idx+1] |= 0x40;
	}
	else
	{
		AuthDa[idx+1] &= ~0x40;
	}
	if(sys_sim == SYS_SIM_FAULE)
	{
		AuthDa[idx+1] |= 0x80;
	}
	else if(sys_sim == SYS_SIM_NORMAL)
	{
		AuthDa[idx+1] &= ~0x80;
	}	
	AuthDa[idx+0] = 0; //B24
	if((n808_gsen_sensor_state_get()&0x08) == 0x08)//非法位移
	{
		AuthDa[idx+0] |= 0x10;
	}
	else
	{
		AuthDa[idx+0] &= ~0x10;
	}
	if((n808_gsen_sensor_state_get()&0x01) == 0x01)//碰撞
	{
		AuthDa[idx+0] |= 0x20;
	}
	else
	{
		AuthDa[idx+0] &= ~0x20;
	}
	if((n808_gsen_sensor_state_get()&0x02) == 0x02)//侧翻
	{
		AuthDa[idx+0] |= 0x40;
	}
	else
	{
		AuthDa[idx+0] &= ~0x40;
	}
	idx += 4;
	//byte0
	if((data_vehicle.Ignition_status&0x08) == 0x08){
	AuthDa[idx+3] |= 0x01;
	}else{
	AuthDa[idx+3] &= ~(0x01);	
	}
	if(gnss_info.gnss_position_info.pos_flag == 1){
	AuthDa[idx+3] |= (0x02);
	}else{
	AuthDa[idx+3] &= ~(0x02);	
	}
	AuthDa[idx+3] &= ~(0x04);
	AuthDa[idx+3] &= ~(0x08);
	if((data_vehicle.Charge_status&0x01) == 0x01){
	AuthDa[idx+3] &= ~(0x10);
	}else if((data_vehicle.Charge_status&0x02) == 0x02){
	AuthDa[idx+3] |= (0x10);	
	}else{
	AuthDa[idx+3] &= ~(0x10);	
	}
	if((data_vehicle.Ignition_status&0x04) == 0x04){
	AuthDa[idx+3] |= (0x20);		
	}else{
	AuthDa[idx+3] &= ~(0x20);	
	}
	if((data_vehicle.Charge_status&0x03) != 0x00){
	AuthDa[idx+3] |= (0x40);			
	}else{
	AuthDa[idx+3] &= ~(0x40);
	}
	if((data_vehicle.relay_sta&0x01) != 0x00){
	AuthDa[idx+3] |= (0x80);
	}else{
	AuthDa[idx+3] &= ~(0x80);	
	}	
	//byte1 00：P档； 01：D档； 02 N档； 03 R档
	if((data_vehicle.brake_gear&0x04) == 0x04){
	AuthDa[idx+2] = 0x00;		
	}else if((data_vehicle.brake_gear&0x20) == 0x20){
	AuthDa[idx+2] = 0x02;	
	}else if((data_vehicle.brake_gear&0x10) == 0x10){
	AuthDa[idx+2] = 0x01;	
	}else if((data_vehicle.brake_gear&0x08) == 0x08){
	AuthDa[idx+2] = 0x03;		
	}else {
	AuthDa[idx+2] = 0x02;	
	}
	if(((data_vehicle.Charge_status&0x04) == 0x04) ||
		((data_vehicle.Charge_status&0x08) == 0x08))
	{
	AuthDa[idx+2] |= (1<<2);		
	}
	else{
	AuthDa[idx+2] &= ~(1<<2);		
	}
	AuthDa[idx+2] &= ~(1<<3);
	if((data_vehicle.lock&0x01) == 0x01){
	AuthDa[idx+2] &= ~(1<<4);
	}else{
	AuthDa[idx+2] |= (1<<4);	
	}	
	if((data_vehicle.doors_status&0x3f) != 0)
	{
	AuthDa[idx+2] |= (1<<5);	
	}else{
	AuthDa[idx+2] &= ~(1<<5);		
	}
	if((data_vehicle.doors_status&0x02) == 0x02)
	{
	AuthDa[idx+2] |= (1<<6);		
	}else
	{
	AuthDa[idx+2] &= ~(1<<6);	
	}
	if((data_vehicle.doors_status&0x04) == 0x04){
	AuthDa[idx+2] |= (1<<7);		
	}else{
	AuthDa[idx+2] &= ~(1<<7);		
	}
	//byte2
	if((data_vehicle.doors_status&0x01) == 0x01){
	AuthDa[idx+1] |= (1<<0);		
	}else{
	AuthDa[idx+1] &= ~(1<<0);		
	}
	if((data_vehicle.doors_status&0x10) == 0x10){
	AuthDa[idx+1] |= (1<<1);		
	}else{
	AuthDa[idx+1] &= ~(1<<1);		
	}
	#if USER_HXJH
	if((data_vehicle.lights_status&0xC0) != 0x00){ /*雾灯*/
	AuthDa[idx+1] |= (1<<2);	
	}else{
	AuthDa[idx+1] &= ~(1<<2);	
	}
	#else
	AuthDa[idx+1] |= (1<<2);
	#endif
	if((data_vehicle.lock&0x04) == 0x04){
	AuthDa[idx+1] &= ~(1<<3);	
	}else{
	AuthDa[idx+1] |= (1<<3);	
	}
	if((data_vehicle.doors_status&0x08) == 0x08){
	AuthDa[idx+1] |= (1<<4);		
	}else{
	AuthDa[idx+1] &= ~(1<<4);		
	}
	if((data_vehicle.Ignition_status&0x02) == 0x02){
	AuthDa[idx+1] |= (1<<5);		
	}else{
	AuthDa[idx+1] &= ~(1<<5);	
	}
	if((data_vehicle.brake_gear&0x01) == 0x01){
	AuthDa[idx+1] |= (1<<6);	
	}else{
	AuthDa[idx+1] &= ~(1<<6);	
	}
	if((data_vehicle.other_status&0x01) == 0x01){
	AuthDa[idx+1] |= (1<<7);	
	}else{
	AuthDa[idx+1] &= ~(1<<7);	
	}
	//byte3
	#if USER_HXJH
	if((data_vehicle.win_status&0x10) != 0x00){
	AuthDa[idx+0] |= (1<<0);	
	}else{
	AuthDa[idx+0] &= ~(1<<0);	
	}
	#else
	if(( data_vehicle.doors_status &0x20 ) == 0x20 )
	{
		AuthDa[idx+0] |= (1<<0);
	}
	else
	{
		AuthDa[idx+0] &= ~(1<<0);
	}
	#endif
	if((data_vehicle.brake_gear&0x02) == 0x02){
	AuthDa[idx+0] |= (1<<1);
	}else{
	AuthDa[idx+0] &= ~(1<<1);	
	}
	if((data_vehicle.lights_status&0x08) == 0x08){
	AuthDa[idx+0] |= (1<<2);	
	}else{
	AuthDa[idx+0] &= ~(1<<2);	
	}	
	if((data_vehicle.lights_status&0x10) == 0x10){
	AuthDa[idx+0] |= (1<<3);	
	}else{
	AuthDa[idx+0] &= ~(1<<3);	
	}	
	if((data_vehicle.lights_status&0x01) == 0x01){
	AuthDa[idx+0] |= (1<<4);	
	}else{
	AuthDa[idx+0] &= ~(1<<4);	
	}	
	if((data_vehicle.lights_status&0x02) == 0x02){
	AuthDa[idx+0] |= (1<<5);	
	}else{
	AuthDa[idx+0] &= ~(1<<5);	
	}	
	if((data_vehicle.lights_status&0x04) == 0x04){
	AuthDa[idx+0] |= (1<<6);	
	}else{
	AuthDa[idx+0] &= ~(1<<6);	
	}	
	if((data_vehicle.win_status&0x0f) != 0x00){
	AuthDa[idx+0] |= (1<<7);	
	}else{
	AuthDa[idx+0] &= ~(1<<7);	
	}			

    idx += 4; 
	{	
		u32toHex4(gnss_info.gnss_position_info.latitude,term_id);
	}

    memcpy(&AuthDa[idx],term_id, 4);	//lat
    idx += 4;
	{
   	 	u32toHex4(gnss_info.gnss_position_info.longitude,term_id);
	}
	
    memcpy(&AuthDa[idx],term_id, 4);	//long
    idx += 4;
	AuthDa[idx] = (gnss_info.gnss_position_info.speed)>>8;
	AuthDa[idx+1] = (gnss_info.gnss_position_info.speed)%0x100;
	//memset(&AuthDa[idx], 0, 2);//gaocheng
	idx += 2;
 	//memset(&AuthDa[idx], 0, 2);//sudu
	AuthDa[idx] = (data_vehicle.speed)>>8;
	AuthDa[idx+1] = (data_vehicle.speed)%0x100;
	idx += 2;   
    //memset(&AuthDa[idx], 0, 2);//fangxiang
	AuthDa[idx] = ( gnss_info.gnss_position_info.direction ) >> 8;
	AuthDa[idx+1] = ( gnss_info.gnss_position_info.direction )%0x100;
	idx += 2;
 	//时间
	AuthDa[idx++] = (uint8_t)(Location_Time.year&0xff);	//YY
	AuthDa[idx++] = Location_Time.month;	//MM
	AuthDa[idx++] = Location_Time.day;
	AuthDa[idx++] = Location_Time.hour;
	AuthDa[idx++] = Location_Time.minute;
	AuthDa[idx++] = Location_Time.second; 

	if(data_vehicle.Electricity != 0)
	{
		u32toHex4(data_vehicle.Endurance_mileage, &AuthDa[idx]);
		AuthDa[idx] = data_vehicle.Electricity;	
	}
	else
	{
		u32toHex4(data_vehicle.Endurance_mileage, &AuthDa[idx]);
	}
	if(data_vehicle.Oil != 0)
	{
		u32toHex4(data_vehicle.Oil,&AuthDa[idx]); //0.1L
		if(data_vehicle.Electricity != 0)
		{
			AuthDa[idx] = data_vehicle.Electricity;	
		}
	}
    idx += 4; 

	#if (USERODO_FROM_GPS == 1)
	u32toHex4(gaoz_gnss_mileage_get()/100,&AuthDa[idx]);//0.1Km
	#else
	u32toHex4(data_vehicle.Odo*10,&AuthDa[idx]);//0.1Km
	#endif
    idx += 4; 

	AuthDa[idx++] = (data_vehicle.bat_vol/100)>>8;
	AuthDa[idx++] = (data_vehicle.bat_vol/100);

	u32toHex4(gnss_info.gnss_position_info.sat_num+		//表示卫星颗数
		gnss_info.gnss_position_info.gga_fs*100+		//表示定位方式
		agnss_location_st_get()*1000+					//表示AGPS定位状态
		vehiclect_runing_state_get()*10000+				//表示车辆控制状态
		gaoz_gnss_lbs_position_type_read() *1000000+										//LBS定位状态,预留
		(sys_gps+1)*10000000+							// GPS运行状态
		gnss_info.gnss_position_info.pos_static*100000000,		//0：无定位 1：静态定位 2：动态定位
		&AuthDa[idx]);
    idx += 4; 
	{
		uint8_t net_signal = 0 ;
		net_module_run_state_get(NET_SIGNAL,&net_signal);
		AuthDa[idx++] = net_signal; //rssi
	}
    AuthDa[idx++] = 0; //lanyazaixiangmoshi 
	/*氧气传感器数据*/
	u16toHex2(data_vehicle.oxygen_sensors,&AuthDa[idx]); 
    idx += 2;
	//AuthDa[idx++] = 0; //jiujingdu
    //AuthDa[idx++] = 0; //jiasudu 
	
	memcpy(pDa,AuthDa,idx);
	return idx;
}
/** ****************************************************************************
* @remarks      uint16_t positioninfo(uint8_t sel,uint8_t *da)
* @brief          位置信息
* @param[in]     sel 0:0504 1:0560
* @param[out]    *da缓存区
* @return        缓存区长度 
* @attention     
*******************************************************************************/
uint16_t positioninfo(uint8_t sel,uint8_t *da)
{
	uint8_t lbsInfoLen = 0;
	uint8_t lbsInofBuf[200];
    uint8_t idx = 0;
	uint8_t AuthDa[500] = { 0 };	
	uint16_t txLen = 0,payloadlen = 0;
	uint32_t sys_status = 0;
	gnss_info_struct gnss_info = {0};

	//Message_ID
	idx = 0;
	if(sel == 0)
	{
		memcpy(&AuthDa[idx], "\x05\x04",2);
	}
	else
	{
		memcpy(&AuthDa[idx], "\x05\x60",2);
	}
	idx += 2;
	//Message_Property,afterward
	idx += 2;
	//Terminal_Num
	if(memcmp(taginf.ManageID,"\x0\x0\x0\x0\x0\x0",6) == 0)
	{
		return 0;
	}
	memcpy(&AuthDa[idx],taginf.ManageID, 6);
	idx += 6;
	//Message_Serial_Number
	AuthDa[idx++] = (uint8_t)(appserialNum >> 8);
	AuthDa[idx++] = (uint8_t)(appserialNum);
	appserialNum ++;
	if (appserialNum > 0x8000)
	{
		appserialNum = 1;
	}
	//內容
	payloadlen = uploadposition(&AuthDa[idx]);

	gnss_lbs_position_type_clear();//主平台上报完位置信息后清除掉基站定位标识
	idx += payloadlen;
	gaoz_log_debug_printf(INFOR_MODE,"800b","******gaoz_gnss_mileage_get<<<<<<<[%d],agnss_location_st_get[%d],runstate[%d],uploadposition[%d]\n", gaoz_gnss_mileage_get(),agnss_location_st_get(),national808_ctrllock_state_get(),payloadlen);
#if ( USER_ERR_CODE == 1 )
	//附加包0x30
	{
		uint32_t err_codecnt=0;
		uint8_t err_code[100] = {0};
		err_codecnt = gaoz_log_error_code_list_total_read(err_code);
		//err_codecnt = 5;
		//memcpy(err_code,"\x12\x34\x56\x78\x90",5);
		AuthDa[idx++] = 0x30;
		AuthDa[idx++] = err_codecnt&0xff;
		if(err_codecnt > 100)
		{
			err_codecnt = 100;			
		}
		if(err_codecnt != 0)
		{
			memcpy(&AuthDa[idx],err_code,err_codecnt);	
			idx += err_codecnt;
			memcpy(gerr_code,err_code,err_codecnt);
		}
		else
		{
			memset((uint8_t *)gerr_code, 0x00 , ERR_CODE_CONFIG);
		}
	}
#endif
	
#if( USER_YH == 1 )
	//附加包0x05
	AuthDa[idx++] = 0x16;
	AuthDa[idx++] = sizeof( vehicle_warmcar_package_data_t );
	idx += warmcarbms_msg_read( &AuthDa[idx] );
#endif
	
	//附加包0x11
	AuthDa[idx++] = 0x11;
	AuthDa[idx++] = 8;
	sys_status = gaoz_event_input_data_get(EVENT_SYSTEMSTATUS);
	u32toHex4(sys_status,&AuthDa[idx]);
	idx += 4;
	memset(&AuthDa[idx],0,4);
	idx += 4;

	/*附加包0x13 胎压数据*/
	AuthDa[idx++] = 0x13;
	AuthDa[idx++] = 10;
	idx += vehicle_tire_pressure_data_get( (uint8_t *)&AuthDa[idx] );

	log_debug_printf( DEBUG_MODE, LBS_MAN_NAME, "LBS--0504--idx = %d \r\n",idx);
     
	lbsInfoLen = get_lbs_cellinfo(lbsInofBuf);

	if(lbsInfoLen )/*LBS 附加包*/
	{
		log_debug_printf( DEBUG_MODE, LBS_MAN_NAME, "--0504--get_lbs_cellinfo lbsInfoLen = %d \r\n",lbsInfoLen);
    
		AuthDa[idx++] = 0x20;
		AuthDa[idx++] = lbsInfoLen; 
		memcpy(&AuthDa[idx],lbsInofBuf,lbsInfoLen); 
		idx += lbsInfoLen;
	}
  
	log_debug_printf( DEBUG_MODE, LBS_MAN_NAME, "LBS---0504--idx = %d \r\n",idx);

	/*附加包0x21 神州扩展状态字*/
	AuthDa[idx++] = 0x21; 
	idx += sz_ext_status_get( (uint8_t *)&AuthDa[idx] );

	/* 附加包 0x25 车辆新状态附加包 */
	AuthDa[idx++] = 0x25; 
	idx += vehicle_new_info_0504_25_info_get( (uint8_t *)&AuthDa[idx] );

	// 附加包0x23
	AuthDa[idx++] = 0x23;
	AuthDa[idx++] = 3;
	gnss_info_old_get(&gnss_info);
	AuthDa[idx++] = gnss_info.gnss_position_info.snr;
	AuthDa[idx++] = gnss_info.gnss_position_info.valid_gps_total_num_sat;
	AuthDa[idx++] = gnss_info.gnss_position_info.valid_bd_total_num_sat;
	
	//消息体属性
	txLen = idx + 1;
	if (txLen < 13)
	{
		txLen = 13;
	}
	AuthDa[2] = (uint8_t)((txLen - 13) >> 8);
	AuthDa[3] = (uint8_t)(txLen - 13);
	//校验
	AuthDa[idx] = get_chk_xor(AuthDa, idx);
	idx ++;

    return msgtranslation(AuthDa,da, idx);
}

/** ****************************************************************************
* @remarks      uint16_t generalrespond(national808_net_devres_msg_t *res_msg,uint8_t *da)
* @brief          通用应答
* @param[in]     national808_net_devres_msg_t网络应答结果
* @param[out]    *da缓存区
* @return        缓存区长度  
* @attention     
*******************************************************************************/
static uint16_t generalrespond(national808_net_devres_msg_t *res_msg,uint8_t *da)
{
	uint8_t tmpDa[300];
	
	//消息头，共用部分		
	tmpDa[0] = 0x05;
	tmpDa[1] = 0x20;
	
	//car ID
	if(res_msg->respondcmd == 0x9571)
	{
		memcpy(&tmpDa[4], curinf.ManageID, 6);
	}
	else
	{
		memcpy(&tmpDa[4], taginf.ManageID, 6);
	}

	//流水号
	tmpDa[10] = (uint8_t)(appserialNum >> 8);
	tmpDa[11] = (uint8_t)(appserialNum & 0xff);
	appserialNum++;
	if (appserialNum > 0x8000)
	{
		appserialNum = 1;
	}
	//应答流水号
	tmpDa[12] = (uint8_t)(res_msg->respondsn>>8);
	tmpDa[13] = (uint8_t)(res_msg->respondsn);

	//应答ID
	tmpDa[14] = (uint8_t)(res_msg->respondcmd>>8);
	tmpDa[15] = (uint8_t)(res_msg->respondcmd);
	//结果
	tmpDa[16] = res_msg->respondsta;
	//属性
	tmpDa[2] = 0;
	tmpDa[3] = 5;
	//校验
	tmpDa[17] = get_chk_xor(tmpDa,17);
	
    return msgtranslation(tmpDa,da,18);
}
/** ****************************************************************************
* @remarks      uint16_t rsarespond(national808_net_devres_msg_t *res_msg,uint8_t *da)
* @brief         查询密钥
* @param[in]     national808_net_devres_msg_t网络应答结果
* @param[out]    *da缓存区
* @return        缓存区长度 
* @attention     
*******************************************************************************/
static uint16_t rsarespond(national808_net_devres_msg_t *res_msg,uint8_t *da)
{
	uint8_t tmpDa[500];
	uint16_t index = 0;
	//消息头，共用部分		
	tmpDa[index++] = 0x05;
	tmpDa[index++] = 0x81;
	
	//car ID
	index = 4;
	memcpy(&tmpDa[index], taginf.ManageID, 6);
	index += 6;
	//流水号
	tmpDa[index++] = (uint8_t)(appserialNum >> 8);
	tmpDa[index++] = (uint8_t)(appserialNum & 0xff);
	appserialNum++;
	if (appserialNum > 0x8000)
	{
		appserialNum = 1;
	}
	//消息头，共用部分		
	tmpDa[index++] = (uint8_t)(res_msg->respondsn>>8);
	tmpDa[index++] = (uint8_t)(res_msg->respondsn);
	//应答ID
	tmpDa[index++] = (uint8_t)(res_msg->respondcmd>>8);
	tmpDa[index++] = (uint8_t)(res_msg->respondcmd);
	//公钥和长度
	tmpDa[index++] = (u8)( strlen((char *)bluetooth_getrsa())>>8);
	tmpDa[index++] = (u8)( strlen((char *)bluetooth_getrsa()));
	memcpy(&tmpDa[index], bluetooth_getrsa(), strlen((char *)bluetooth_getrsa()));
	index += strlen((char *)bluetooth_getrsa());
	//蓝牙名称和长度
	tmpDa[index++] = strlen((char *)bluetooth_getname());
	memcpy(&tmpDa[index], bluetooth_getname(), strlen((char *)bluetooth_getname()));
	index += strlen((char *)bluetooth_getname());
	//属性
	tmpDa[2] = (uint8_t)((index - 12) >> 8);
	tmpDa[3] = (uint8_t)(index - 12);
	//校验
	tmpDa[index] = get_chk_xor(tmpDa,index);
	index++;
	
    return msgtranslation(tmpDa,da,index);
}
/** ****************************************************************************
* @remarks      uint16_t qxwzrespond(national808_net_devres_msg_t *res_msg,uint8_t *da)
* @brief         查询密钥
* @param[in]     national808_net_devres_msg_t网络应答结果
* @param[out]    *da缓存区
* @return        缓存区长度 
* @attention     
*******************************************************************************/
static uint16_t qxwzrespond(national808_net_devres_msg_t *res_msg,uint8_t *da)
{
	uint8_t tmpDa[200];
	uint16_t index = 0;
	qxwz_save_cfg_infor_t qwxz_cfg_t = {0};
	uint32_t ret = pdFAIL;
	//消息头，共用部分		
	tmpDa[index++] = 0x06;
	tmpDa[index++] = 0x36;
	
	//car ID
	index = 4;
	memcpy(&tmpDa[index], taginf.ManageID, 6);
	index += 6;
	//流水号
	tmpDa[index++] = (uint8_t)(appserialNum >> 8);
	tmpDa[index++] = (uint8_t)(appserialNum & 0xff);
	appserialNum++;
	if (appserialNum > 0x8000)
	{
		appserialNum = 1;
	}
	//消息头，共用部分		
	tmpDa[index++] = (uint8_t)(res_msg->respondsn>>8);
	tmpDa[index++] = (uint8_t)(res_msg->respondsn);
	//应答ID
	tmpDa[index++] = (uint8_t)(res_msg->respondcmd>>8);
	tmpDa[index++] = (uint8_t)(res_msg->respondcmd);
	//key和长度
	ret = gaoz_qxwz_inject_cfg_save_flash_read(&qwxz_cfg_t);		
	if(ret == pdFAIL)
	{
		gaoz_log_debug_printf(INFOR_MODE,"800b","gaoz_qxwz_inject_cfg_save_flash_read fail\n");
	}	
	else
	{
		tmpDa[index++] = strlen((char *)qwxz_cfg_t.app_key);
		if(strlen((char *)qwxz_cfg_t.app_key) != 0)
		{
			memcpy(&tmpDa[index], qwxz_cfg_t.app_key, strlen((char *)qwxz_cfg_t.app_key));
		}
		index += strlen((char *)qwxz_cfg_t.app_key);

		tmpDa[index++] = strlen((char *)qwxz_cfg_t.app_secret);
		if(strlen((char *)qwxz_cfg_t.app_secret) != 0)
		{
			memcpy(&tmpDa[index], qwxz_cfg_t.app_secret, strlen((char *)qwxz_cfg_t.app_secret));
		}
		index += strlen((char *)qwxz_cfg_t.app_secret);

		tmpDa[index++] = strlen((char *)qwxz_cfg_t.device_id);
		if(strlen((char *)qwxz_cfg_t.device_id) != 0)
		{
			memcpy(&tmpDa[index], qwxz_cfg_t.device_id, strlen((char *)qwxz_cfg_t.device_id));
		}
		index += strlen((char *)qwxz_cfg_t.device_id);

		tmpDa[index++] = strlen((char *)qwxz_cfg_t.device_type);
		if(strlen((char *)qwxz_cfg_t.device_type) != 0)
		{
			memcpy(&tmpDa[index], qwxz_cfg_t.device_type, strlen((char *)qwxz_cfg_t.device_type));
		}
		index += strlen((char *)qwxz_cfg_t.device_type);
	}
	//属性
	tmpDa[2] = (uint8_t)((index - 12) >> 8);
	tmpDa[3] = (uint8_t)(index - 12);
	//校验
	tmpDa[index] = get_chk_xor(tmpDa,index);
	index++;
	
    return msgtranslation(tmpDa,da,index);
}
/** ****************************************************************************
* @remarks      uint16_t updateresult(update_result_t *upslt,uint8_t *da)
* @brief         升级结果
* @param[in]     *upslt升级结果队列
* @param[out]    *da缓存区
* @return        缓存区长度 
* @attention     
*******************************************************************************/
static uint16_t updateresult(update_result_t *upslt,uint8_t *da)
{
	uint8_t tmpDa[300];
	
	//消息头，共用部分		
	tmpDa[0] = 0x01;
	tmpDa[1] = 0x08;
	
	//car ID
	memcpy(&tmpDa[4], taginf.ManageID, 6);

	//流水号
	tmpDa[10] = (uint8_t)(appserialNum >> 8);
	tmpDa[11] = (uint8_t)(appserialNum & 0xff);
	appserialNum++;
	if (appserialNum > 0x8000)
	{
		appserialNum = 1;
	}
	//升级类型
	tmpDa[12] = (uint8_t)(upslt->update_types);
	//结果
	tmpDa[13] = upslt->update_result;
	//属性
	tmpDa[2] = 0;
	tmpDa[3] = 2;
	//校验
	tmpDa[14] = get_chk_xor(tmpDa,14);
	
    return msgtranslation(tmpDa,da,15);
}

/** ****************************************************************************
* @remarks       uint16_t lockrespond(national808_net_devres_msg_t *res_msg,uint8_t *da)
* @brief         异步锁上报
* @param[in]     national808_net_devres_msg_t网络应答结果
* @param[out]    *da缓存区
* @return        缓存区长度 
* @attention     
*******************************************************************************/	
static uint16_t lockrespond(uint8_t *da, national808_ctrllock_msg_t *res_msg)
{
	uint8_t tmpDa[300];
	uint16_t idx = 0;
	
	//消息头，共用部分		
	tmpDa[idx++] = (uint8_t)(res_msg->lock_res.respondcmd>>8)&0x0f;
	tmpDa[idx++] = (uint8_t)(res_msg->lock_res.respondcmd&0xff);
	
	//car ID
	idx = 4;
	memcpy(&tmpDa[idx], taginf.ManageID, 6);
	idx += 6;
	//流水号
	tmpDa[idx++] = (uint8_t)(appserialNum >> 8);
	tmpDa[idx++] = (uint8_t)(appserialNum & 0xff);
	appserialNum++;
	if (appserialNum > 0x8000)
	{
		appserialNum = 1;
	}
	//应答流水号
	tmpDa[idx++] = (uint8_t)(res_msg->lock_res.respondsn>>8);
	tmpDa[idx++] = (uint8_t)(res_msg->lock_res.respondsn&0xff);

	//应答ID
	tmpDa[idx++] = (uint8_t)(res_msg->lock_res.respondcmd>>8); //0x95;
	tmpDa[idx++] = (uint8_t)(res_msg->lock_res.respondcmd&0xff);// 0x63;
	//结果
	tmpDa[idx++] = res_msg->lock_res.respondsta;
	if(res_msg->lock_res.respondsta == 1)
	{
		tmpDa[idx++] = (uint8_t)(res_msg->lock_err >> 8);
		tmpDa[idx++] = (uint8_t)(res_msg->lock_err & 0xff);	
	}
	//属性
	if(res_msg->lock_res.respondsta == 0)
	{
		tmpDa[2] = 0;
		tmpDa[3] = 5;
	}
	else
	{
		tmpDa[2] = 0;
		tmpDa[3] = 7;		
	}
	//校验
	tmpDa[idx] = get_chk_xor(tmpDa,idx);
	idx ++;

	vehicle_info_report_semaphore_put();//主动上报一条0504

    return msgtranslation(tmpDa,da,idx);
}
/** ****************************************************************************
* @remarks     static uint16_t pkekeyrsp(national808_net_devres_msg_t *res_msg, uint8_t *da)
* @brief         查询pkekey
* @param[in]    
* @param[out]    *da缓存区
* @return        缓存区长度 
* @attention     
*******************************************************************************/
static uint16_t pkekeyrsp(national808_net_devres_msg_t *res_msg, uint8_t *da)
{
	uint8_t idx;
	uint8_t AuthDa[256];	
	uint16_t txLen;

	//Message_ID
	idx = 0;
	//if(res_msg->respondsta == 3){
	//	memcpy(&AuthDa[idx], "\x06\x01",2);
	//}
	//else{
		memcpy(&AuthDa[idx], "\x06\x05",2);
	//}
	idx += 2;

	idx += 2;

	//Terminal_Num
	memcpy(&AuthDa[idx],taginf.ManageID, 6);
	idx += 6;

	//Message_Serial_Number
	AuthDa[idx++] = (uint8_t)(appserialNum >> 8);
	AuthDa[idx++] = (uint8_t)(appserialNum);
	appserialNum ++;
	if (appserialNum > 0x8000)
	{
		appserialNum = 1;
	}
	//payload
	memcpy(&AuthDa[idx], &pke_key, sizeof(pke_key));
	idx += sizeof(pke_key);
	//消息体属性
	txLen = idx + 1;
	if (txLen < 13)
	{
		txLen = 13;
	}
	AuthDa[2] = (uint8_t)((txLen - 13) >> 8);
	AuthDa[3] = (uint8_t)(txLen - 13);

	//校验
	AuthDa[idx] = get_chk_xor(AuthDa, idx);
	idx ++;

    return msgtranslation(AuthDa,da, idx);
}	
/** ****************************************************************************
* @remarks     static uint16_t pkekeyupload( uint8_t *da)
* @brief         查询pkekey
* @param[in]    
* @param[out]    *da缓存区
* @return        缓存区长度 
* @attention     
*******************************************************************************/
static uint16_t pkekeyupload( uint8_t *da)
{
	uint8_t idx;
	uint8_t AuthDa[256];	
	uint16_t txLen;

	//Message_ID
	idx = 0;
	memcpy(&AuthDa[idx], "\x06\x37",2);
	idx += 2;
	//property
	idx += 2;

	//Terminal_Num
	memcpy(&AuthDa[idx],taginf.ManageID, 6);
	idx += 6;

	//Message_Serial_Number
	AuthDa[idx++] = (uint8_t)(appserialNum >> 8);
	AuthDa[idx++] = (uint8_t)(appserialNum);
	appserialNum ++;
	if (appserialNum > 0x8000)
	{
		appserialNum = 1;
	}
	//payload
	memcpy(&AuthDa[idx], &mcu_pkekey, sizeof(mcu_send_pkekey_t));
	idx += sizeof(mcu_send_pkekey_t);
	//消息体属性
	txLen = idx + 1;
	if (txLen < 13)
	{
		txLen = 13;
	}
	AuthDa[2] = (uint8_t)((txLen - 13) >> 8);
	AuthDa[3] = (uint8_t)(txLen - 13);

	//校验
	AuthDa[idx] = get_chk_xor(AuthDa, idx);
	idx ++;

    return msgtranslation(AuthDa,da, idx);
}		
/** ****************************************************************************
* @remarks      uint16_t msgtranslation(uint8_t *da,uint8_t *txbuf, uint16_t len)
* @brief          转译
* @param[in]     *da缓存区,len缓存区长度 
* @param[out]    *txbuf缓存区
* @return        txbuf缓存区长度  
* @attention     
*******************************************************************************/
static uint16_t msgtranslation(uint8_t *da,uint8_t *txbuf, uint16_t len)
{
	uint16_t j = 0,txindex = 0, encrypt_len = 0;
	uint8_t pdata[1024 + 30]={0};
	uint8_t *data = da;
#if( USER_AES_ENCRYPT_N800 == 1 )
	uint16_t serial_number = 0;
#endif
	if (len < 1024)
	{
		memcpy(data, da, len);
	}
	else
	{
		return 0;
	}
	/*原始数据进行AES加密*/	
	encrypt_len = len;
#if( USER_AES_ENCRYPT_N800 == 1 )
	/*判断当前发送得数据包是否为注册，如果是则原文发送数据否则进行数据加密*/
	if(( data[0] != 0x01 ) && ( data[1] != 0x00 ))
	{ 
                        
		serial_number = ( data[10] * 256 + data[11] );
		national808_encrypt_package( (uint8_t *)data, (uint16_t *)&encrypt_len, serial_number ); 
                        
		national808_encrypt_package_shell( (uint8_t *)data, (uint16_t *)&encrypt_len );	 
                        
	}
#endif
	txindex = 0;
	pdata[txindex ++] = 0x7e;
	//消息转译
	for(j = 0;j < encrypt_len; j ++)
	{
		if(*data == 0x7E)
		{
			pdata[txindex ++] = 0x7D;
			pdata[txindex ++] = 0x02;
		}
		else if(*data == 0x7D)
		{
			pdata[txindex ++] = 0x7D;
			pdata[txindex ++] = 0x01;
		} 
		else 
		{
			pdata[txindex ++] = *data;
		}

		data ++;
	}

	pdata [txindex ++] = 0x7E;
    memcpy(txbuf,pdata, txindex);

    return txindex;
}
/** ****************************************************************************
* @remarks       uint8_t init_paratable(uint8_t * ManageID,uint8_t *da,uint16_t *len)
* @brief          可外部调用初始参数表
* @param[in]      ManageID设备id
* @param[out]     *da缓存区,*len缓存区长度
* @return         0成功 
* @attention     
*******************************************************************************/
uint8_t init_paratable(uint8_t * ManageID,uint8_t *da,uint16_t *len)
{
	return initTerminalParaAll(ManageID,da,len);
}
/** ****************************************************************************
* @remarks       uint8_t initTerminalParaAll(uint8_t * ManageID,uint8_t *da,uint16_t *len)
* @brief          初始参数表
* @param[in]      ManageID设备id
* @param[out]    *da缓存区,*len缓存区长度
* @return         0成功 
* @attention     
*******************************************************************************/
static uint8_t initTerminalParaAll(uint8_t * ManageID,uint8_t *da,uint16_t *len)
{
	uint8_t check;
	uint16_t i;
	
	//因为之前老版本都是1~3，新版本中如果发现参数表校验错误，会重写车辆ID，从原来的4有效字节，变成6字节。
	taginf.Subject = 0x05;	//科目
	taginf.IP1Len = 0x0D;	//主IP长度
	memcpy(taginf.IP1, "\x34\x37\x2E\x39\x33\x2E\x32\x33\x35\x2E\x32\x34\x36\x0", 14);	//主IP
	taginf.Port1Len = 0x05;	//主端口长度
	memcpy(taginf.Port1,"\x34\x30\x30\x30\x30", 5);		//主端口
	taginf.IP2Len = 0x0D;	//备用IP长度 
	memcpy(taginf.IP2, "\x34\x37\x2E\x39\x33\x2E\x32\x33\x35\x2E\x32\x34\x36\x0", 14);	//备用IP	
	taginf.Port2Len = 0x05;	//备用端口长度
	memcpy(taginf.Port2, "\x34\x30\x30\x30\x30", 5);		//备用端口

	taginf.Mode = 0x10;	//工作模式 
	taginf.Voltage = 0x01;	//电瓶电压 "1-12V 2-24V 3-36V",17
	taginf.SpeedLimit = 0x78;	//限速
	memcpy(taginf.ManageID, ManageID, 6);	//车辆管理ID

	memcpy(taginf.KValue, "\x0E\x10",2);	//K值
	memcpy(taginf.Term_Num, "\x01\x38\x88\x88\x88\x88",6);	//手机号
	taginf.CameraErr = 0x01;	//摄像头故障处理， 1就是强制摄像头必须OK才能使用，0无所谓了
	taginf.PicInterval = 60;	//拍照间隔	
	//memcpy(taginf.FallLimit, "\x00\x20",2);	//离线时长限制
	taginf.VoiceSwitch = 1; //语音提示开关  1-开  0-关
	taginf.ZKSwitch = 0;	//字库更新开关，初始为0，更新后为1, 暂时没用
	memcpy(taginf.APN,  "CMNET\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0",16); //CMNET
	taginf.APNLen = 5;
	memcpy(taginf.USER, "CMNET\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0",16); //CMNET
	taginf.USERLen = 5;
	memcpy(taginf.PWD,  "CMNET\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0",16); //CMNET
	taginf.PWDLen = 5;

	taginf.AuthCodeFlag = 0;	//鉴权码，如果为A1代表已存储鉴权码，其它没有
	memset(taginf.AuthCode, 0xff, 4);	//4字节鉴权码

	memset(taginf.ProvinceID, '0', 2);
	memset(taginf.TownID, '0', 2);

	taginf.CarColor = '0';	//车牌颜色，按照JT/T415-2006 的5.4.12。未上牌时，取值为0。
	memset(taginf.CarMark, '8', 20);//车牌颜色为0 时，表示车辆VIN；否则，表示公安交通管理部门颁发的机动车号牌。

	memcpy(taginf.heartBeatDly, "\x0\x0\x0\x1E", 4); //终端心跳发送间隔，单位为秒（s）默认120 s


	memcpy(taginf.idleReportMaxTime, "\x0\x0\x02\x58", 4);	//休眠时汇报时间间隔，单位为秒（s） 	//不教学
	memcpy(taginf.workReportMaxTime, "\x0\x0\x00\x3c", 4);	//缺省时间汇报间隔，单位为秒（s）		//教学中
	memcpy(taginf.idleReportMaxMeter, "\x0\x0\x0\xc8", 4);	//休眠时汇报距离间隔，单位为米（m），>0
	memcpy(taginf.workReportMaxMeter, "\x0\x0\x0\xc8", 4);	//缺省距离汇报间隔
	memcpy(taginf.ACCoffReportCellTime, "\x0\x0\x02\x58", 4);	//休眠时汇报时间间隔，单位为秒（s） 	//不教学
	memcpy(taginf.ACConReportCellTime, "\x0\x0\x00\x3c", 4);	//缺省时间汇报间隔，单位为秒（s）

	taginf.crashTime = 2;	//碰撞报警参数设置：b7-b0： 碰撞时间，单位4ms

	taginf.crashG = 35;		//碰撞加速度，单位 0.1g

	//侧翻报警参数设置：侧翻角度，单位1度，默认为30度
	memcpy(taginf.CarAngle,"\x0\x1e",2);
	
	//车辆里程表读数，1/10km
	memset(taginf.CarKm, 0, 4);
	
	taginf.SpkTips = 0;

	memcpy(&taginf.SetPhone[0], "15801319948", 11);
	memcpy(&taginf.SetPhone[11], "13811315562", 11);
	memcpy(&taginf.SetPhone[22], "18001356415", 11);
	memset(&taginf.SetPhone[33], '0', 77);

//	memset(taginf.vinbuf,0,17);

	taginf.Check = 0;

	check=0;
	for(i=0;i<sizeof(terminal_info_t)-1;i++)
	{
		check^=*((uint8_t*)&taginf+i);		
	}
	*((uint8_t*)&taginf+sizeof(terminal_info_t)-1)=check;
	if((da != NULL) && (len != NULL))
	{
		memcpy(da,&taginf,sizeof(terminal_info_t));
		*len = sizeof(terminal_info_t);
	}

	return 0;
}

/** ****************************************************************************
* @remarks       int readTerminalPara(const INT8 *filename)
* @brief          读取参数表
* @param[in]      *filename文件路径
* @param[out]     无
* @return         <0失败 0成功
* @attention     
*******************************************************************************/
static int readTerminalPara(const INT8 *filename)
{
	uint8_t check = 0;
	int fd = fibo_file_open(filename, FS_O_RDONLY);
    if (fd < 0)
    { 
        return -1;
    }
    char *temp = (char *)fibo_malloc(1024*1);
    if (temp == NULL)
    { 
		return -1;
        //OSI_LOGI(0, "readTerminalPara %u", (unsigned int)temp);
    }
	memset(temp,0,1024);
	INT32 file_offset = fibo_file_seek(fd,8,FS_SEEK_CUR); 
	if(file_offset < 0)
	{
		//OSI_LOGI(0, "fibo_file_seek fail"); 
		return -1;
	}
    int ret = fibo_file_read(fd, (UINT8 *)temp, sizeof(terminal_info_t));
    if (ret < 0)
    {
        fibo_file_close(fd);
        free(temp); 
		return -1;
    }
	if(strlen(temp) == 0)
    {
        fibo_file_close(fd);
        free(temp); 
		return -1;
    }
	check = get_chk_xor((uint8_t *)temp,sizeof(terminal_info_t));
	if(check != 0)
	{
        fibo_file_close(fd);
        free(temp);	 
		return -1;
	}
	memcpy(&taginf,temp,sizeof(terminal_info_t));
    fibo_file_close(fd);
    free(temp);

    return 0;
}
/** ****************************************************************************
* @remarks       static int saveserviceloadpara(uint8_t *pDa,uint8_t type,uint8_t *pDa2)
* @brief         存储配置
* @param[in]     无
* @param[out]    无
* @return        0失败 1成功
* @attention
*******************************************************************************/
static int saveserviceloadpara(uint8_t *pDa,uint8_t type,uint8_t *pDa2)
{
	uint8_t check;
	int ret = -1;
	terminal_info_t current_info={0};

    char *temp = (char *)gaoz_fibo_malloc(1024*1);
    if (temp == NULL)
    {
       return 0;/* 失败 */
    }
	memcpy(&current_info,&taginf,sizeof(terminal_info_t));
    switch (type)
	{
		case 1:	//注册的消息，保存鉴权码
			memcpy(current_info.AuthCode, pDa, 4);
			current_info.AuthCodeFlag = 0xA1;
			gaoz_log_debug_printf(INFOR_MODE,"800b","current_info.AuthCode = %02x,%02x,%02x,%02x",current_info.AuthCode[0],current_info.AuthCode[1],current_info.AuthCode[2],current_info.AuthCode[3]);
			/*保存通信密钥和存储数据密钥*/
			current_info.rs[0] = 0x01;
			memcpy( (uint8_t *)&current_info.rs[1], (uint8_t *)&pDa[4], 16 );		/*通信密钥*/
			current_info.rs[17] = 0x01;
			memcpy( (uint8_t *)&current_info.rs[18], (uint8_t *)&pDa[20], 16 );	/*存储密钥*/
			break;
		case 2:	//终端注销状态
			current_info.AuthCodeFlag = 0xff;
			memset(current_info.AuthCode, 0xff, 4);
			memset((uint8_t *)current_info.rs, 0x00, sizeof( current_info.rs ));
			break;
		case 3:	//存主IP
			memset(current_info.IP1, 0, sizeof(current_info.IP1));
			current_info.IP1Len = *pDa2;
			memcpy(current_info.IP1, pDa, current_info.IP1Len);
			break;
		case 4:	//存主端口
			memset(current_info.Port1, 0, sizeof(current_info.Port1));
			current_info.Port1Len = *pDa2;
			memcpy(current_info.Port1, pDa, current_info.Port1Len);
			break;
		case 5:	//存副IP
			memset(current_info.IP2, 0, sizeof(current_info.IP2));
			current_info.IP2Len = *pDa2;
			memcpy(current_info.IP2, pDa, current_info.IP2Len);
			break;
		case 6:	//存副端口
			memset(current_info.Port2, 0, sizeof(current_info.Port2));
			current_info.Port2Len = *pDa2;
			memcpy(current_info.Port2, pDa, current_info.Port2Len);
			break;
		//设置电瓶电压 "1-12V 2-24V 3-36V",17
		case 7:
			if ( (*pDa >= '1') && (*pDa <= '3') )
			{
				current_info.Voltage = *pDa - '0';
			}
			else
			{
				current_info.Voltage = 1;
			}
			break;

		//请输入限速值
		case 8:
			if (*pDa >= 130)
			{
				*pDa = 130;
			}
		
			current_info.SpeedLimit = *pDa;
			break;
		//输入新ID号
		case 9:
			memcpy(current_info.ManageID, pDa, 6);		//20160125 原来是4字节，改成6字节
			break;
		//请输入拍照间隔
		case 10:
			current_info.PicInterval = *pDa;
			break;
			//请输入新手机号
		case 11:
			memcpy(current_info.Term_Num, pDa, 6);	//手机号
			break;
		//摄像头故障处理， 0-不启用，1-启用
		case 12:
			if ( (*pDa == 0) || (*pDa == 1) )
			{
				current_info.CameraErr = *pDa;
			}
			else
			{
				current_info.CameraErr = 0;
			}
			break;

		//语音提示开关  1-开  0-关
		case 13:
			current_info.VoiceSwitch = (*pDa & 0x01);
			break;

		case 14:
			current_info.SpkTips = (*pDa & 0x01);
			break;

		case 15:
			current_info.Subject = (*pDa & 0x0F);
			break;

		case 16:
			memcpy(current_info.SetPhone, pDa, 110);
			break;
		
		case 17:
			memcpy(current_info.KValue, pDa, 2);
			break;

		case 18:

			break;

		case 19:

			break;			
			
		case 20:

			break;
		case 21:	//APN名称
			memset(current_info.APN, 0, sizeof(current_info.APN));
			current_info.APNLen = *pDa2;
			memcpy(current_info.APN, pDa, current_info.APNLen);
			break;
		case 22:	//APN用户名称
			memset(current_info.USER, 0, sizeof(current_info.USER));
			current_info.USERLen = *pDa2;
			memcpy(current_info.USER, pDa, current_info.USERLen);
			break;
		case 23:	//APN密码
			memset(current_info.PWD, 0, sizeof(current_info.PWD));
			current_info.PWDLen = *pDa2;
			memcpy(current_info.PWD, pDa, current_info.PWDLen);
			break;
		case 24:	//点火时汇报电池信息时间间隔

			memcpy(current_info.ACConReportCellTime, pDa, 4);
			break;
		case 25:	//熄火时汇报电池信息时间间隔

			memcpy(current_info.ACCoffReportCellTime, pDa, 4);
			break;

		}
		
		check = get_chk_xor((uint8_t*)(&current_info), sizeof(terminal_info_t)-1);
		current_info.Check = check;
		gaoz_log_debug_printf(INFOR_MODE,"800b","saveserviceloadpara <--%s,%d",&current_info,sizeof(terminal_info_t));
		memcpy(temp,terminid,4);
		memcpy(&temp[4],"EDTT",4);
		memcpy(&temp[8],&current_info,sizeof(terminal_info_t));
		ret = file_termpara_write(TERMID_FILE,temp,sizeof(terminal_info_t)+8);
		if(ret < 0)
		{
			//default;
			initTerminalParaAll(terminid,NULL,NULL);//default;
			gaoz_fibo_free(temp);	
			return 0;
		}
		flash_spi_sector_erase(SF_SYS_PARA_FLAG_ADDR);
		ret = flash_spi_write_data(SF_SYS_PARA_FLAG_ADDR,(uint8_t *)temp,sizeof(terminal_info_t)+8);
		if(ret == pdPASS)
		{
			gaoz_log_debug_printf(INFOR_MODE,"800b",">>SF_SYS_PARA_FLAG_ADDR Okay<<");	
		}
		flash_spi_sector_erase(SF_SYS_PARA_BACKUP_ADDR);
		ret = flash_spi_write_data(SF_SYS_PARA_BACKUP_ADDR,(uint8_t *)temp,sizeof(terminal_info_t)+8);
		if(ret == pdPASS)
		{
			gaoz_log_debug_printf(INFOR_MODE,"800b",">>SF_SYS_PARA_BACKUP_ADDR Okay<<");
		}
		memcpy(&taginf,&current_info,sizeof(terminal_info_t));
		gaoz_fibo_free(temp);	
		return 1;
}
/** ****************************************************************************
* @remarks       uint32_t savemajorip(terminal_info_t *info,uint8_t flag)
* @brief         存储参数表
* @param[in]     参数表，标记是否需要重启网络
* @param[out]    无
* @return        1失败 0成功
* @attention
*******************************************************************************/
uint32_t savemajorip(terminal_info_t *info,uint8_t flag)
{
	UINT8 check = 0;
	int ret = 0;

	if(info == NULL)
	{
		return 1;
	}
	char *temp = (char *)gaoz_fibo_malloc(1024*1);
    if (temp == NULL)
    {
        return 1;
    }
	memset(temp,0,1024);

	check = get_chk_xor((uint8_t*)(info), sizeof(terminal_info_t)-1);
	info->Check = check;
	memcpy(temp,terminid,4);	
	memcpy(&temp[4],"EDTT",4);
	memcpy(&temp[8],info,sizeof(terminal_info_t));
	ret = file_termpara_write(TERMID_FILE,temp,sizeof(terminal_info_t)+8);
	if(ret < 0)
	{
		gaoz_fibo_free(temp);	
		return 1;
	}	
	flash_spi_sector_erase(SF_SYS_PARA_FLAG_ADDR);
	ret = flash_spi_write_data(SF_SYS_PARA_FLAG_ADDR,(uint8_t *)temp,sizeof(terminal_info_t)+8);
	if(ret == pdPASS)
	{
		gaoz_log_debug_printf(INFOR_MODE,"800b",">>SF_SYS_PARA_FLAG_ADDR Okay<<");
	}
	flash_spi_sector_erase(SF_SYS_PARA_BACKUP_ADDR);
	ret = flash_spi_write_data(SF_SYS_PARA_BACKUP_ADDR,(uint8_t *)temp,sizeof(terminal_info_t)+8);
	if(ret == pdPASS)
	{
		gaoz_log_debug_printf(INFOR_MODE,"800b",">>SF_SYS_PARA_FLAG_ADDR Okay<<");
	}
	memcpy(&taginf,info,sizeof(terminal_info_t));
	if(flag == 2)
	{
		/* 重启设备 */
		net_rst = NET_RST_END;
	}
	gaoz_fibo_free(temp);
	return 0;
}

/** ****************************************************************************
* @remarks       uint8_t setParafromservice(uint8_t * da, uint16_t len)
* @brief         存储参数表
* @param[in]     无
* @param[out]    无
* @return        1失败 0成功
* @attention
*******************************************************************************/
static uint8_t setParafromservice(uint8_t * da, uint16_t len)
{
	UINT32 paraID = 0;
	UINT8 ParaLen = 0;
	UINT8 * pParaDa;
	UINT16 len_cur; //保证参数在总长度内
	UINT8 ParaCnt;

	UINT8 para_cur;	
	int ret = 0;
	INT8 rebootflag = 0;
	INT8 pTmpDa[128]={0};

	UINT8 uint8_tTmpDa = 0;
	UINT8 check = 0;
	terminal_info_t current_info={0};
	mangpatio_info_t minor_info={0};
	uint32_t ulTmpDa = 0;
	uint8_t vinbuf[18];

	char *temp = (char *)gaoz_fibo_malloc(1024*1);
    if (temp == NULL)
    {
        return 1;
    }

	/**/
	memcpy(&current_info,&taginf,sizeof(terminal_info_t));
	memcpy(&minor_info,&terinf,sizeof(mangpatio_info_t));//minor
	ParaCnt = *da;
	len_cur = 1;
	pParaDa = &da[1];

	//for(int i = 0,j = 0,k = 0;i < len;i += (5*k+j))
	for (para_cur=0;para_cur<ParaCnt;para_cur++)
	{
		paraID = hex4CombineOne(pParaDa);
		pParaDa += 4;
		ParaLen = pParaDa[0];
		pParaDa ++;
		len_cur += 5;
		len_cur += ParaLen;
		if (len_cur > len)
		{
			ret = 1;
			break;
		}
		/*
		paraID = hex4CombineOne(&da[i]);
		j += da[i+4];
		k++;
		ParaLen = da[i+4];
		gaoz_log_debug_printf(INFOR_MODE,"800b","paraID=%x,ParaLen=%d,j=%d,k=%d,len=%d\r\n",paraID,ParaLen,j,k,len);
		*/
		if(paraID == 0x0001)
		{
			if(ParaLen != 4)
			{
					ret = 1;
					break;					
			}
			memcpy(current_info.heartBeatDly, pParaDa, ParaLen);
			#if 1
			gaoz_log_debug_printf(INFOR_MODE,"800b","current_info.heartBeatDly=%d",hex4CombineOne(current_info.heartBeatDly));
			#endif
		}
		else if(paraID == 0x0013)
		{
			if ((judgeIpType(pParaDa, ParaLen) == 0) ||
				(get_valid_domain_name((char *)pParaDa, ParaLen) == 0))
			{
				memset(current_info.IP1,0,sizeof(current_info.IP1));
				memcpy(current_info.IP1, pParaDa, ParaLen);
				current_info.IP1Len = ParaLen;
				rebootflag = 1;
			}
			else
			{
				ret = 1;
				break;
			}
			#if 1
			gaoz_log_debug_printf(INFOR_MODE,"800b","current_info.IP1=%s,%d",current_info.IP1,current_info.IP1Len);
			#endif
		}
		else if(paraID == 0x0017)
		{
			if ((judgeIpType(pParaDa, ParaLen) == 0) ||
				(get_valid_domain_name((char *)pParaDa, ParaLen) == 0))
			{
				memset(current_info.IP2,0,sizeof(current_info.IP2));
				memcpy(current_info.IP2,pParaDa, ParaLen);
				current_info.IP2Len = ParaLen;
				rebootflag = 1;
			}
			else
			{
				ret = 1;
				break;
			}
			#if 1
			gaoz_log_debug_printf(INFOR_MODE,"800b","current_info.IP2=%s,%d",current_info.IP2,current_info.IP2Len);
			#endif
		}
		else if(paraID == 0x0018)
		{
			if (ParaLen > 4)
			{
				ret = 1;
				break;
			}
			Int_To_ASCII_p(hex4CombineOne(pParaDa), pTmpDa, &uint8_tTmpDa);
			gaoz_log_debug_printf(INFOR_MODE,"800b","Int_To_ASCII_p=%s,%d\r\n",pTmpDa,uint8_tTmpDa);
			if (uint8_tTmpDa > 5)
			{
				ret = 1;
				break;
			}
			memcpy(current_info.Port1, pTmpDa, uint8_tTmpDa);
			current_info.Port1Len = uint8_tTmpDa;
			memcpy(current_info.Port2, pTmpDa, uint8_tTmpDa);
			current_info.Port2Len = uint8_tTmpDa;
			rebootflag = 1;
		#if 1
			gaoz_log_debug_printf(INFOR_MODE,"800b","Port1=%d,Port2=%d\r\n",hex4CombineOne((uint8_t *)current_info.Port1),hex4CombineOne((uint8_t *)current_info.Port2));
		#endif				
		}
		else if(paraID == 0x0027)
		{
			if (ParaLen != 4)
			{
				ret = 1;
				break;
			}
			memcpy(current_info.idleReportMaxTime, pParaDa, ParaLen);
		#if 1
			gaoz_log_debug_printf(INFOR_MODE,"800b","current_info.idleReportMaxTime=%d",hex4CombineOne(current_info.idleReportMaxTime));
		#endif
		}
		else if(paraID == 0x0029)
		{
			if (ParaLen != 4)
			{
				ret = 1;
				break;
			}
			memcpy(current_info.workReportMaxTime, pParaDa, ParaLen);
		#if 1
			gaoz_log_debug_printf(INFOR_MODE,"800b","current_info.workReportMaxTime=%d",hex4CombineOne(current_info.workReportMaxTime));
		#endif
		}
		else if(paraID == 0x002C)
		{
			if (ParaLen != 4)
			{
				ret = 1;
				break;
			}
			memcpy(current_info.idleReportMaxMeter, pParaDa, ParaLen);
		#if 1
			gaoz_log_debug_printf(INFOR_MODE,"800b","current_info.idleReportMaxMeter=%d",hex4CombineOne(current_info.idleReportMaxMeter));
		#endif
		}
		else if(paraID == 0x002E)
		{
			if (ParaLen != 4)
			{
				ret = 1;
				break;
			}
			memcpy(current_info.workReportMaxMeter, pParaDa, ParaLen);
		#if 1
			gaoz_log_debug_printf(INFOR_MODE,"800b","current_info.workReportMaxMeter=%d",hex4CombineOne(current_info.workReportMaxMeter));
		#endif
		}
		else if(paraID == 0x0030)
		{
			
		}
		else if(paraID == 0x0031)
		{
			
		}
		else if(paraID == 0x0032)
		{
			
		}
		else if(paraID == 0x0033)
		{
			
		}
		else if(paraID == 0x0034)
		{
			
		}
		else if(paraID == 0x0035)
		{
			
		}
		else if(paraID == 0x00FF0105)
		{
			if (ParaLen > 4)
			{
				ret = 1;
				break;
			}
			ulTmpDa = hex4CombineOne(pParaDa);//单位百米
			gaoz_gnss_mileage_set(ulTmpDa*100);
		}
 
		else if(paraID == 0x00FF0108)
		{
			memset(vinbuf,0,18);
			memcpy(vinbuf,pParaDa,17);//copy vin
 			
			if( vin_data_verification( (char *)vinbuf ) == pdPASS )
			{ 
				if(vehicle_set_vin(vinbuf) == pdPASS)
				{
					ret = 0;
					gaoz_log_debug_printf(INFOR_MODE,"800b","set VIN set pdpass vin:%s\r\n",vinbuf);
				} 
				else
				{
					ret = 1;
					gaoz_log_debug_printf(INFOR_MODE,"800b","set VIN set pdfail vin:%s\r\n",vinbuf);
				} 
			} 
			else 
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","set VIN verification pdfail vin:%s\r\n",vinbuf);
				ret = 1;//设置失败
				break;
			} 
		} 
		else if(paraID == 0x00FF0904)
		{
			if (ParaLen != 1)
			{
				ret = 1;
				break;
			}
			if((pParaDa[0] == 0x01) || (pParaDa[0] == 0x10))
			{
				if(current_info.Mode != 0x10)
				{
					rebootflag = 3;
				}
				current_info.Mode = pParaDa[0];
			}
			else if((pParaDa[0] == 0x02) || (pParaDa[0] == 0x20))
			{
				minor_info.Mode = pParaDa[0];
				rebootflag = 2;
			}
		}
		else
		{
			ret = 1;
			#if 1
			gaoz_log_debug_printf(INFOR_MODE,"800b",">>no paraID<<");
			#endif			
		}
		pParaDa += ParaLen; //指针指到下一个开始的位置		
	}
	if(ret)
	{
		gaoz_fibo_free(temp);
		return ret;
	}

	check = get_chk_xor((uint8_t*)(&current_info), sizeof(terminal_info_t)-1);
	current_info.Check = check;
	gaoz_log_debug_printf(INFOR_MODE,"800b","9529 <--%s,%d\r\n",(current_info.Port1),sizeof(terminal_info_t));
	memcpy(temp,terminid,4);	
	memcpy(&temp[4],"EDTT",4);
	memcpy(&temp[8],&current_info,sizeof(terminal_info_t));

	 
	ret = file_termpara_write(TERMID_FILE,temp,sizeof(terminal_info_t)+8);
	if(ret < 0)
	{
		gaoz_fibo_free(temp);	
		return 1;
	}	
	flash_spi_sector_erase(SF_SYS_PARA_FLAG_ADDR);
	ret = flash_spi_write_data(SF_SYS_PARA_FLAG_ADDR,(uint8_t *)temp,sizeof(terminal_info_t)+8);
	if(ret == pdPASS)
	{
		gaoz_log_debug_printf(INFOR_MODE,"800b",">>SF_SYS_PARA_FLAG_ADDR Okay<<");
	}
	flash_spi_sector_erase(SF_SYS_PARA_BACKUP_ADDR);
	ret = flash_spi_write_data(SF_SYS_PARA_BACKUP_ADDR,(uint8_t *)temp,sizeof(terminal_info_t)+8);
	if(ret == pdPASS)
	{
		gaoz_log_debug_printf(INFOR_MODE,"800b",">>SF_SYS_PARA_FLAG_ADDR Okay<<");
	}
	memcpy(&taginf,&current_info,sizeof(terminal_info_t));
	if(rebootflag == 1)
	{
		rebootflag = 0;
		/* 重启设备 */
		net_rst = NET_RST_START;
	#if 1
		/* 2022.05.09 YXX 检测辅助平台网络连接正常时，辅助平台将网络断开*/
		if( mangpatio_socket_state_get() == SOCKET_LINK_CREATE_OK )
		{
			mangpatio_broken_link = 1;
		}
	#else/*不能直接销毁标志位，导致辅助平台网络不能正常断开*/
		mangpatio_socket_state_set(SOCKET_LINK_CREATE_ERROR);//
	#endif
	}
	else if(rebootflag == 2)
	{
		ret = saveminorip(&minor_info,2);
		if(ret != 0)
		{
			gaoz_log_debug_printf(INFOR_MODE,"800b",">>saveminorip fail<<");
		}
	}
	else if(rebootflag == 3)
	{
		net_rst = NET_RST_END;//禁用
	}
	ret = 0;
	gaoz_fibo_free(temp);
	return ret;
}

/** ****************************************************************************
* @remarks      uint32_t setrelay_sta(uint8_t data)
* @brief        存储断电继电器状态
* @param[in]     data下发状态
* @param[out]    无
* @return       pdPASS成功  pdFAIL失败
* @attention     
*******************************************************************************/
uint32_t setrelay_sta(uint8_t data)
{
	uint32_t ret = pdFAIL;
#if 0
	uint8_t da[3]={0};
	int ret = pdFAIL;	

	if((data != 1)&&(data != 2)){
		return ret;
	}
	da[0] = 0x6A;
	da[1] = data;
	da[2] = get_chk_xor(da,2);
	ret = file_termpara_write(RELAYPARA,(INT8 *)da,3);
	if(ret < 0)
	{
		ret = pdFAIL;
	}
	else
	{
		ret = pdPASS;
	}
	gaoz_log_debug_printf(INFOR_MODE,"800b", "setrelay_sta:%d\r\n",data );
#else	
	/*读取继电器状态，由以前FLASH中读取方式修改为寄存器方式无需L610对状态进行存储，
	频繁读写L610文件系统出现异常，2022.06.16 YXX*/
	if(( data == 0x01 ) || ( data == 0x02 ))
	{
		national_808_relay_state = data;
		ret = pdPASS;
	}
	gaoz_log_debug_printf(DEBUG_MODE,"800b","setrelay_sta = %d,ret = %d\r\n", national_808_relay_state, ret );
#endif
	return ret;
}

/** ****************************************************************************
* @remarks      uint32_t setrelay_sta(uint8_t data)
* @brief        读取断电继电器状态
* @param[in]     无
* @param[out]    继电器状态
* @return       pdPASS成功  pdFAIL失败
* @attention     
*******************************************************************************/
uint32_t readrelay_sta( uint8_t *data )
{
	uint32_t ret = pdFAIL;

	if( data == NULL )
	{
		return pdFAIL;
	}
	if(( national_808_relay_state == 0x01 ) || ( national_808_relay_state == 0x02 ))
	{
		*data = national_808_relay_state;
		ret = pdPASS;
	}
	gaoz_log_debug_printf(DEBUG_MODE,"800b","readrelay_sta = %d,ret = %d\r\n", national_808_relay_state,ret );
	
	return ret;
}

/** ****************************************************************************
* @remarks      uint32_t n808_erase_qxwzkey(void)
* @brief         擦除key
* @param[in]     无
* @param[out]    无
* @return        pdPASS成功 ，  pdFAIL失败
* @attention     无
*******************************************************************************/
static uint32_t n808_erase_qxwzkey(void)
{
	uint32_t ret = pdFAIL;
	qxwz_save_cfg_infor_t qxwz_key_t = {0};

	int fd = fibo_file_open(QXWZKEY,FS_O_RDONLY);
	if(fd < 0)
	{
		gaoz_log_debug_printf(INFOR_MODE,"800b","fibo_file_open(QXWZKEY fail!!");
		ret = pdFAIL;
	}
	else
	{
		int rfd = fibo_file_close(fd);
		if(rfd < 0)
		{
			gaoz_log_debug_printf(INFOR_MODE,"800b","fibo_file_close fail!!");
			ret = pdFAIL;
		} 
		else
		{
			rfd = fibo_file_delete(QXWZKEY);
			if(rfd < 0)
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","fibo_file_delete QXWZKEY fail!!");
				ret = pdFAIL;
			} 
			else
			{
				memset(qxwz_key_t.app_key,0,sizeof(qxwz_key_t.app_key));
				memset(qxwz_key_t.app_secret,0,sizeof(qxwz_key_t.app_secret));
				HexToAsciiString((char *)qxwz_key_t.device_id,(char *)terminid, 4);		
				sprintf((char *)qxwz_key_t.device_type, "%s", QXWZDEVICE_TYPE);
				ret = gaoz_qxwz_inject_cfg_save_flash_write(&qxwz_key_t);
			}
		}
	}

	return ret;
}
/** ****************************************************************************
* @remarks      uint32_t n808_manger_qxwzkey(void)
* @brief         管理key
* @param[in]     无
* @param[out]    无
* @return        pdPASS成功 ，  pdFAIL失败
* @attention     无
*******************************************************************************/
uint32_t n808_manger_qxwzkey(void)
{
	#define KEY_MALLOC    1024*1
	int ret = pdFAIL;
	uint16_t tmpDalen = 0;
	qxwz_save_cfg_infor_t qwxz_cfg_t = {0};

	char *tmpDa = (char *)fibo_malloc(KEY_MALLOC);
	if (tmpDa == NULL)
	{
		return ret;	
	}
	memset(tmpDa,0,KEY_MALLOC);

	ret = gaoz_qxwz_inject_cfg_save_flash_read(&qwxz_cfg_t);		
	if(ret == pdFAIL)
	{
		gaoz_log_debug_printf(INFOR_MODE,"800b","gaoz_qxwz_inject_cfg_save_flash_read fail\n");
		fibo_free(tmpDa);
		return ret;
	}	
	if(( strlen((const char *)qwxz_cfg_t.app_key) == 0 )
    || ( strlen((const char *)qwxz_cfg_t.app_secret) == 0 )
        || ( strlen((const char *)qwxz_cfg_t.device_type) == 0 )
            || ( strlen((const char *)qwxz_cfg_t.device_id) == 0 ))
    {
        gaoz_log_debug_printf(INFOR_MODE,"800b","QXWZ  parameter is invalid!\n");
		fibo_free(tmpDa);
		return ret;
    }

	ret = file_termpara_read(QXWZKEY,tmpDa);
	if(ret < 0)
	{
		gaoz_log_debug_printf(INFOR_MODE,"800b","file_termpara_read QXWZKEY fail!!");
		memset(tmpDa,0,KEY_MALLOC);
		tmpDalen = 0;
		tmpDa[tmpDalen] = strlen((char *)qwxz_cfg_t.app_key);
		if(tmpDa[tmpDalen] != 0)
		{
			tmpDalen ++;
			memcpy(&tmpDa[tmpDalen],qwxz_cfg_t.app_key,strlen((char *)qwxz_cfg_t.app_key));
		}
		tmpDalen += strlen((char *)qwxz_cfg_t.app_key);
		tmpDa[tmpDalen] = strlen((char *)qwxz_cfg_t.app_secret);
		if(tmpDa[tmpDalen] != 0)
		{
			tmpDalen ++;
			memcpy(&tmpDa[tmpDalen],qwxz_cfg_t.app_secret,strlen((char *)qwxz_cfg_t.app_secret));
		}
		tmpDalen += strlen((char *)qwxz_cfg_t.app_secret);
		tmpDa[tmpDalen] = get_chk_xor((u8 *)tmpDa,tmpDalen);
		tmpDalen++;
		ret = file_termpara_write(QXWZKEY,(INT8 *)tmpDa,tmpDalen);
		if(ret < 0)
		{
			ret = pdFAIL;
		}
		else
		{
			ret = pdPASS;
		}
	}
	else
	{
		if((memcmp(&tmpDa[1],(char *)qwxz_cfg_t.app_key,strlen((char *)qwxz_cfg_t.app_key)) != 0) ||
			(memcmp(&tmpDa[tmpDa[0]+2],(char *)(qwxz_cfg_t.app_secret),strlen((char *)qwxz_cfg_t.app_secret)) != 0))
		{
			gaoz_log_debug_printf(INFOR_MODE,"800b","file_termpara_read ////gaoz_qxwz_inject_cfg_save_flash_read compare fail!!");
			memset(tmpDa,0,CKIDFR_MALLOC);
			tmpDalen = 0;
			tmpDa[tmpDalen] = strlen((char *)qwxz_cfg_t.app_key);
			if(tmpDa[tmpDalen] != 0)
			{
				tmpDalen ++;
				memcpy(&tmpDa[tmpDalen],qwxz_cfg_t.app_key,strlen((char *)qwxz_cfg_t.app_key));
			}
			tmpDalen += strlen((char *)qwxz_cfg_t.app_key);
			tmpDa[tmpDalen] = strlen((char *)qwxz_cfg_t.app_secret);
			if(tmpDa[tmpDalen] != 0)
			{
				tmpDalen ++;
				memcpy(&tmpDa[tmpDalen],qwxz_cfg_t.app_secret,strlen((char *)qwxz_cfg_t.app_secret));
			}
			tmpDalen += strlen((char *)qwxz_cfg_t.app_secret);
			tmpDa[tmpDalen] = get_chk_xor((u8 *)tmpDa,tmpDalen);
			tmpDalen++;
			ret = file_termpara_write(QXWZKEY,(INT8 *)tmpDa,tmpDalen);
			if(ret < 0)
			{
				ret = pdFAIL;
			}
			else
			{
				ret = pdPASS;
			}			
		}
	}
	
	
	fibo_free(tmpDa);

	return ret;
}
/** ****************************************************************************
* @remarks      static uint32_t n808_match_pkekey(uint8_t *msg,uint16_t len)
* @brief         匹配pkekey
* @param[in]     无
* @param[out]    无
* @return        pdPASS成功 ，  pdFAIL失败
* @attention     无
*******************************************************************************/
static uint32_t n808_match_pkekey(uint8_t *msg,uint16_t len)
{
	int ret = pdFAIL;
	uint8_t save_msg[100] = {0};
	pkekey_dev_t pke_key_tmp = {0};

	if((msg == NULL) || (len < sizeof(pkekey_dev_t)))
	{
		return ret;
	}

	if(memcmp(&pke_key,msg,len) != 0)
	{
		memcpy(&pke_key_tmp,msg,sizeof(pkekey_dev_t));
		memcpy(save_msg,&pke_key_tmp,sizeof(pkekey_dev_t));
		save_msg[sizeof(pkekey_dev_t)] = get_chk_xor(save_msg,sizeof(pkekey_dev_t));
		ret = file_termpara_write(PKEKEY,(INT8 *)save_msg,sizeof(pkekey_dev_t)+1);
		if(ret < 0)
		{
			ret = pdFAIL;
		}
		else
		{
			memcpy(&pke_key,&pke_key_tmp,sizeof(pkekey_dev_t));
			ret = pdPASS;
		}
	}
	else
	{
		ret = pdPASS;
	}

	return ret;
}
/** ****************************************************************************
* @remarks      static uint32_t n808_save_pkekey(uint8_t *msg,uint16_t len)
* @brief         
* @param[in]     无
* @param[out]    无
* @return        pdPASS成功 ，  pdFAIL失败
* @attention     无
*******************************************************************************/
static uint32_t n808_save_pkekey(uint8_t *msg,uint16_t len)
{
	int ret = pdFAIL;
	uint8_t save_msg[100] = {0};
	pkekey_dev_t pke_key_tmp = {0};

	if((msg == NULL) || (len < sizeof(pkekey_dri_t)))
	{
		return ret;
	}

	if((msg[0] > 0) && (msg[0] < 5))
	{
		memcpy(&pke_key_tmp,&pke_key,sizeof(pkekey_dev_t));
		pke_key_tmp.key_app[msg[0]-1].key_sn = msg[0];
		memcpy(pke_key_tmp.key_app[msg[0]-1].key_encode,&msg[1],4);
		memcpy(pke_key_tmp.key_app[msg[0]-1].key_rollcode,&msg[5],4);
		memcpy(save_msg,&pke_key_tmp,sizeof(pkekey_dev_t));
		save_msg[sizeof(pkekey_dev_t)] = get_chk_xor(save_msg,sizeof(pkekey_dev_t));
		ret = file_termpara_write(PKEKEY,(INT8 *)save_msg,sizeof(pkekey_dev_t)+1);
		if(ret < 0)
		{
			ret = pdFAIL;
		}
		else
		{
			memcpy(&pke_key,&pke_key_tmp,sizeof(pkekey_dev_t));
			ret = pdPASS;
		}
	}
	else
	{
		ret = pdFAIL;
	}

	return ret;
}
/** ****************************************************************************
* @remarks      static uint32_t n808_read_pkekey(void)
* @brief         
* @param[in]     无
* @param[out]    无
* @return        pdPASS成功 ，  pdFAIL失败
* @attention     无
*******************************************************************************/
static uint32_t n808_read_pkekey(void)
{
	int ret = pdFAIL;
	uint8_t save_msg[100] = {0};

	ret = file_termpara_read(PKEKEY,(INT8 *)save_msg);
	if(ret < 0)
	{
		ret = pdFAIL;
	}
	else
	{
		memcpy(&pke_key,save_msg,sizeof(pkekey_dev_t));
		ret = pdPASS;
	}
	return ret;
}



/** ****************************************************************************
* @remarks       static void parsepatio_protocol(uint8_t * temp, uint16_t len)
* @brief         协议解析 
* @param[in]     * temp缓存区，len长度
* @param[out]    无
* @return        无
* @attention     
*******************************************************************************/
static void parsepatio_protocol(uint8_t * temp, uint16_t len)
{
 	uint8_t reDa = 0;
	int ret = -1;
	national_net_res_msg_t patiores_msg;
	national808_net_devres_msg_t devres_msg;
	national808_ctrllock_msg_t  ctlock_msg;
	qxwz_save_cfg_infor_t qxwz_key_t = {0};
	//报文解析使用,文件头
	uint16_t Message_ID;
	uint16_t Message_Property;
	uint8_t Terminal_ID[6];
	uint16_t Message_Serial_Number;
	uint8_t *pMsgBody;

	uint16_t getSerialNum;
	uint16_t getID;
	uint8_t getResult;
	rtc_struct rtc = { 0 };

	//u8 CryptFlag;
	u16 bodyLen;
	uint8_t secret_key[32] = { 0 };

 	uint8_t *tmpDa = (uint8_t *)gaoz_fibo_malloc(1024*2);
    if (tmpDa == NULL)
    {
		return;
    }
	if (len < 1024)
	{
		memcpy(tmpDa, temp, len);
		{
		#if 1
			uint8_t debug_buf[1024] = {0};
			uint16_t debug_buf_len = 0;
			memset(debug_buf,0,sizeof(debug_buf));
            debug_buf_len = HexToAsciiString((char *)debug_buf,(char *)tmpDa, len);
			debug_buf[debug_buf_len] = '\r';
            debug_buf_len++;
            debug_buf[debug_buf_len] = '\n';
            debug_buf_len++;
			gaoz_log_debug_printf(INFOR_MODE,"800b", "parsepatio_protocol:%s,%d\r\n",debug_buf, debug_buf_len );
		#endif
		}
	}
	else
	{
		gaoz_fibo_free(tmpDa);
		return;
	}
	
	Message_ID = (tmpDa[0]<<8)+tmpDa[1];					//消息ID
	if( Message_ID == 0x5001 )
	{
		national808_decrypt_package_shell( (uint8_t *)tmpDa, (uint16_t *)&len );
		if (len == 0)
		{
			return;
		}
		Message_ID = (tmpDa[0] << 8) + tmpDa[1];					//消息ID
		Message_Property = ((tmpDa[2] << 8) + tmpDa[3]);	//消息体属性
		memcpy(Terminal_ID, &tmpDa[4], 6);
		Message_Serial_Number = (tmpDa[10] << 8) + tmpDa[11];		//下发流水账号码
		//pMsgBody = &tmpDa[12];								//消息体
		//消息体
		if ((Message_Property & 0x2000) == 0x2000)
		{
			pMsgBody = &tmpDa[16];
		}
		else
		{
			pMsgBody = &tmpDa[12];
		}
		Message_Property &= 0x3FF;
		bodyLen = Message_Property;
		//CryptFlag = (tmpDa[2] >> 2) & 0x07;
		//if (CryptFlag != 0x00)
		//{
		national808_decrypt_package((uint8_t *)pMsgBody, (uint16_t *)&bodyLen, Message_Serial_Number);
		//}
	}
	else
	{
		Message_Property = ((tmpDa[2] << 8) + tmpDa[3]);	//消息体属性
		memcpy(Terminal_ID, &tmpDa[4], 6);
		Message_Serial_Number = (tmpDa[10] << 8) + tmpDa[11];		//下发流水账号码
		//pMsgBody = &tmpDa[12];								//消息体
		//消息体
		if ((Message_Property & 0x2000) == 0x2000)
		{
			pMsgBody = &tmpDa[16];
		}
		else
		{
			pMsgBody = &tmpDa[12];
		}
		Message_Property &= 0x3FF;
		bodyLen = Message_Property;
		// CryptFlag = (tmpDa[2] >> 2) & 0x07;
		// if (CryptFlag != 0x00)
		// {
		// 	national808_decrypt_package(pMsgBody, &bodyLen, Message_Serial_Number);
		// }
	}
	switch (Message_ID)
	{
		case 0x8100:
		{
			switch(pMsgBody[2])
			{
				case 0:
					gaoz_log_debug_printf(INFOR_MODE,"800b","welcome");
					//先解密，之后再存储，这个是socket通信秘钥
					memcpy(secret_key, Terminal_ID, 6);
					secret_key[6] = (u8)(Message_Serial_Number >> 8);
					secret_key[7] = (u8)(Message_Serial_Number);
					strReverse(secret_key, &secret_key[8], 8);
					aes_decrypt_multi(&pMsgBody[7], 16, secret_key);
					aes_decrypt_multi(&pMsgBody[23], 16, secret_key);
					ret = saveserviceloadpara(&pMsgBody[3],1,NULL);
					patiores_msg.commane = TER_RESPONSE_REG;
					patiores_msg.results = ret;
					ret = national808_net_patiores_queue_put(&patiores_msg);
					if(ret < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 8100 fail!\r\n");
					} 
					break;
				case 1:
					gaoz_log_debug_printf(INFOR_MODE,"800b","car reg");
					break;
				case 2:
					gaoz_log_debug_printf(INFOR_MODE,"800b","no car");
					break;
				case 3:
					gaoz_log_debug_printf(INFOR_MODE,"800b","ter reg");
					break;
				case 4:
					gaoz_log_debug_printf(INFOR_MODE,"800b","no ter");
					break;
				case 5:
					gaoz_log_debug_printf(INFOR_MODE,"800b","no sim");
					break;
				default:
					gaoz_log_debug_printf(INFOR_MODE,"800b","error");
					break;
			}
		} 
		break;
		case 0x8107:
		{
			patiores_msg.commane = TER_QUERY_SYS_VERSION;
			patiores_msg.results = pdPASS;
			ret = national808_net_patiores_queue_put(&patiores_msg);
			if(ret < 1)
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 8107 fail!\r\n");
			}
		}
		break;
		case 0x9501:
		{
			gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9501  body[4] == %d\r\n",pMsgBody[4]);
			switch(pMsgBody[4])
			{
				case 0:
				{
					rtc.year = pMsgBody[5] + 0x2000;
					rtc.month = pMsgBody[6];
					rtc.day = pMsgBody[7];
					rtc.hour = pMsgBody[8];
					rtc.minute = pMsgBody[9];
					rtc.second = pMsgBody[10];
					gaoz_log_debug_printf(INFOR_MODE,"800b","Platform authentication response time:%x-%x-%x %x:%x:%x\r\n",
											rtc.year,rtc.month,rtc.day,rtc.hour,rtc.minute,rtc.second);
					gaoz_rtc_sys_set( RTC_TIM_CAL_BCD, &rtc );

					national808_auth_reason_clear();
				}
				case 1:
				{
					patiores_msg.commane = TER_RESPONSE_AUTH;
					patiores_msg.results = pdPASS;
					ret = national808_net_patiores_queue_put(&patiores_msg);
					if(ret < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9501 fail!\r\n");
					}
				}
				break;
				case 3:
				case 4:
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","9501 error");
					patiores_msg.commane = TER_RESPONSE_AUTH;
					patiores_msg.results = pdFAIL;
					ret = national808_net_patiores_queue_put(&patiores_msg);
					if(ret < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9501 fail!\r\n");
					}
				}
				break;
				default:
				break;
			}

			national808_auth_recv_st = 0;
		}
		break;
		case 0x9520:
		{
			getSerialNum = char2u16(&pMsgBody[0]);
			getID = char2u16(&pMsgBody[2]);
			getResult = pMsgBody[4];
			//gaoz_log_debug_printf(INFOR_MODE,"800b","getSerialNum[%x] getID[%x] getResult[%d]!\r\n",getSerialNum,getID,getResult);
			if(getID == 0x0506)
			{
				patiores_msg.commane = TER_RESPONSE_HEART ;
				patiores_msg.results = pdPASS;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 0506 fail!\r\n");
				}
				gaoz_log_debug_printf(INFOR_MODE,"800b","getSerialNum[%x] getID[%x] getResult[%d]!\r\n",getSerialNum,getID,getResult);
			}
			else if(getID == 0x0003)
			{
				saveserviceloadpara(NULL,2,NULL);	//zhuxiao
			}
			else if(getID == 0x0504)
			{
				patiores_msg.commane = TER_REALTIME_DATA_REQ;
				if(getResult == 0)
				{
					patiores_msg.results = pdPASS;
				}
				else
				{
					patiores_msg.results = pdFAIL;
				}
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 0504 fail!\r\n");
				}
				else
				{
					//gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 0504 ok!\r\n");
				}
			}
			else if(getID == 0x0612)
			{
				patiores_msg.commane = TER_RESPONSE_DATA_UP ;
				patiores_msg.results = pdPASS;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 0612 fail!\r\n");
				}
			}
			else if( getID == 0x0103 )
			{
				patiores_msg.commane = TER_MAINTENANCE_INFOR_UPDATA ;
				patiores_msg.results = pdPASS;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 0103 fail!\r\n");
				}
			}
			else if( getID == 0x0630 )
			{
				patiores_msg.commane = TER_BMS_INFOR_UPDATA ;
				patiores_msg.results = pdPASS;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 0630 fail!\r\n");
				}
			}
			else if( getID == 0x0102 )
			{
				patiores_msg.commane = TER_FAULT_CODE_UPDATA ;
				patiores_msg.results = pdPASS;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 0102 fail!\r\n");
				}
			}
		}
		break;
		case 0x9529:
		{
			gaoz_log_debug_printf(INFOR_MODE,"800b","pMsgBody Message_Property <-,%d", Message_Property);			
			if(pMsgBody[0] >= 1)
			{
				reDa = setParafromservice(pMsgBody,Message_Property);
				patiores_msg.commane = TER_SET_SYS_PARRMETER;
				patiores_msg.results = pdPASS;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9529 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = reDa;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_put 9529 fail!\r\n");
				}	
			}
			else
			{
				patiores_msg.commane = TER_SET_SYS_PARRMETER;
				patiores_msg.results = pdFAIL;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9529 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 1;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9529 fail!\r\n");
				}
			}
		}
		break;
		case 0x9560:
		{
			patiores_msg.commane = TER_QUERY_REALTIME;
			patiores_msg.results = pdPASS;
			ret = national808_net_patiores_queue_put(&patiores_msg);
			if(ret < 1)
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9560 fail!\r\n");
			}
			
		}
		break;
		case 0x9562:
		{
			if( (national808_ctrllock_state_get() == CTLOCK_INIT) ||
				(national808_ctrllock_state_get() == CTLOCK_OK))
			{ 	
				patiores_msg.commane = TER_CONTROL_TER_FLASHING_HORNS;
				patiores_msg.results = pdPASS;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9562 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 0;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_put 9562 fail!\r\n");
				}
	
				if(pMsgBody[0] != 0)
				{
					national808_ctrllock_state_set(CTLOCK_PATIO_SPK);
				}
				if(vehiclect_runing_state_get() == CARCTL_RUNING_INIT)	
				{
					ctlock_msg.lock_type = pMsgBody[0];
					ctlock_msg.lock_res.respondcmd = Message_ID;
					ctlock_msg.lock_res.respondsn = Message_Serial_Number;
					ctlock_msg.lock_res.respondsta = 0; 
					ctlock_msg.lock_err = 0;
					ret = national808_ctlock_queue_put(&ctlock_msg);
					if(ret < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"800b","ctlock_queue_put 9562 fail!\r\n");
					}
				}
				else
				{
					national808_ctrllock_state_set( CTLOCK_OK );		
				}
				
			}
			else
			{ 
				patiores_msg.commane = TER_CONTROL_TER_FLASHING_HORNS;
				patiores_msg.results = pdPASS;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9562 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 0;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_put 9562 fail!\r\n");
				}	
			}
			
		}
		break;	
		case 0x9563:
		{
			if( (national808_ctrllock_state_get() == CTLOCK_INIT) ||
				(national808_ctrllock_state_get() == CTLOCK_OK))
			{ 
				patiores_msg.commane = TER_CONTROL_TERMINAL_ACK;
				patiores_msg.results = pdPASS;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9563 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 0;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9563 fail!\r\n");
				}
				if((pMsgBody[0] == 1) || (pMsgBody[0] == 7))
				{
					national808_ctrllock_state_set(CTLOCK_PATIO_UNLOCK);
					if(pMsgBody[0] == 7)
					{
						setrelay_sta(1);
					}
				}
				else
				{
					national808_ctrllock_state_set(CTLOCK_PATIO_LOCK);
					if(pMsgBody[0] == 8)
					{
						setrelay_sta(2);
					}
				}
				if(vehiclect_runing_state_get() == CARCTL_RUNING_INIT)	
				{
					ctlock_msg.lock_type = pMsgBody[0];
					ctlock_msg.lock_res.respondcmd = Message_ID;
					ctlock_msg.lock_res.respondsn = Message_Serial_Number;
					ctlock_msg.lock_res.respondsta = 0; 
					ctlock_msg.lock_err = 0;
					ret = national808_ctlock_queue_put(&ctlock_msg);
					if(ret < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"800b","ctlock_queue_put 9563 [%d] fail!\r\n",pMsgBody[0]);
					}
				}
				else
				{
					national808_ctrllock_state_set( CTLOCK_OK );	
				}
			}
			else
			{ 
				patiores_msg.commane = TER_CONTROL_TERMINAL_ACK;
				patiores_msg.results = pdFAIL;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9563 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 1;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9563 fail!\r\n");
				}
			}
		}
		break;
		case 0x9565:
		{
			if(setrelay_sta(pMsgBody[0]) == pdPASS)
			{
				patiores_msg.commane = TER_CONTROL_TER_POWER;
				patiores_msg.results = pdPASS;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9565 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 0;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9565 fail!\r\n");
				}
			}
			else
			{
				patiores_msg.commane = TER_CONTROL_TER_POWER;
				patiores_msg.results = pdFAIL;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9565 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 1;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9565 fail!\r\n");
				}
			}
		}	
		break;
		case 0x9108:
		{
			if(cjson_parseurl((char *)pMsgBody,Message_Property,URL_MAJOR) == 1)
			{
				patiores_msg.commane = TER_CONTROL_TER_FOTA;
				patiores_msg.results = pdPASS;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9108 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 0;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9108 fail!\r\n");
				}
			}
			else
			{
				patiores_msg.commane = TER_CONTROL_TER_FOTA;
				patiores_msg.results = pdPASS;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9108 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 1;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9108 fail!\r\n");
				}
			}
		}
		break;
		case 0x9571:
		{
			if ((Message_Property >= 6)&&(chk_valid_bcd_num(pMsgBody, 6) == 1))
			{
					memcpy(curinf.ManageID,taginf.ManageID,6);
					int ret = saveserviceloadpara(pMsgBody,9,NULL);	
					if(ret < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"800b","9571 saveserviceloadpara error");
						patiores_msg.commane = TER_CONTROL_TER_UPDATE_ID;
						patiores_msg.results = pdFAIL;
						ret = national808_net_patiores_queue_put(&patiores_msg);
						if(ret < 1)
						{
							gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9571 fail!\r\n");
						}
						devres_msg.respondcmd = Message_ID;
						devres_msg.respondsn = Message_Serial_Number;
						devres_msg.respondsta = 0;
						ret = national808_net_devres_queue_put(&devres_msg);
						if(ret < 1)
						{
							gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9571 fail!\r\n");
						}
					}
					else
					{
						/*restart authoration*/
						patiores_msg.commane = TER_CONTROL_TER_UPDATE_ID;
						patiores_msg.results = pdPASS;
						ret = national808_net_patiores_queue_put(&patiores_msg);
						if(ret < 1)
						{
							gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9571 fail!\r\n");
						}
						devres_msg.respondcmd = Message_ID;
						devres_msg.respondsn = Message_Serial_Number;
						devres_msg.respondsta = 0;
						ret = national808_net_devres_queue_put(&devres_msg);
						if(ret < 1)
						{
							gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9571 fail!\r\n");
						}
						
					}
			}
			else
			{
				patiores_msg.commane = TER_CONTROL_TER_UPDATE_ID;
				patiores_msg.results = pdFAIL;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9571 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 0;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9571 fail!\r\n");
				}
			}
		}
		break;
		case 0x9574:
		{
			if(pMsgBody[1] == 0x04) //重启
			{
				reset_reason_set(EVENT_RESET_REASON_SERVER_REQUIRE);
				gaoz_sys_abnormal_reset_set( SYS_RESET_APP );
			}
			else if(pMsgBody[1] == 0x07)//重新定位
			{
				gaoz_event_input_data_set( EVENT_VEHICLE , 2);
			}
		}
		break;
		case 0x9575:
		case 0x9576:
		{
			patiores_msg.commane = TER_CONTROL_TER_RESET;
			patiores_msg.results = pdPASS;
			ret = national808_net_patiores_queue_put(&patiores_msg);
			if(ret < 1)
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9575 fail!\r\n");
			}
			devres_msg.respondcmd = Message_ID;
			devres_msg.respondsn = Message_Serial_Number;
			devres_msg.respondsta = 0;
			ret = national808_net_devres_queue_put(&devres_msg);
			if(ret < 1)
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9575 fail!\r\n");
			}
			ret = n808_cle_save_data();
			if(ret != pdPASS)
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","gaoz_save_data_open fail[%d]\n", sfb_handle_id);
			}
			else
			{
				memset(national808_data_st.send_data,0,UNIT_FLASH_DATA_LEN);
				national808_data_st.send_datalen = 0;
				national808_data_st.send_st = N808_SENDRSP_OK;
			}
			
		}
		break;
		case 0x9579:
		{
			uint8_t rsaDa[1024]={0};
			memcpy(rsaDa,pMsgBody,Message_Property);	
			rsaDa[Message_Property] = get_chk_xor(rsaDa,Message_Property);
			ret = file_termpara_write(RSAPARA,(INT8 *)rsaDa,Message_Property+1);
			if(ret < 0)
			{
				patiores_msg.commane = TER_CONTROL_TER_BT_UPDATESE;
				patiores_msg.results = pdFAIL;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9579 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 1;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9579 fail!\r\n");
				}
			}
			else
			{
				patiores_msg.commane = TER_CONTROL_TER_BT_UPDATESE;
				patiores_msg.results = pdPASS;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9579 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 0;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9579 fail!\r\n");
				}
				//if(memcmp(&pMsgBody[hex2CombineOne(pMsgBody)+2+1],bt_getname(),sizeof(bt_getname())) == NULL)
				memset(rsaDa,0,sizeof(rsaDa));
				ret = file_termpara_read(RSAPARA,(INT8 *)rsaDa);
				if(ret == 0)
				{
					bluetooth_setrsa(&rsaDa[2],hex2CombineOne(rsaDa));
					if( bluetooth_getname() == NULL )
					{
						bluetooth_setname(&rsaDa[hex2CombineOne(rsaDa)+2+1],rsaDa[hex2CombineOne(rsaDa)+2]);
						gaoz_log_debug_printf(INFOR_MODE,"800b","bt_getname()= %s,%d", bluetooth_getname(),strlen((char *)bluetooth_getname()));
						/*ret = gaoz_ble_drive_data_close( (char *)bluetooth_getname());
						if(ret == pdPASS)
						{
							gaoz_log_debug_printf(INFOR_MODE,"800b","gaoz_ble_drive_data_close  OKay!\r\n");
						}*/
						ret = gaoz_ble_drive_data_open( (char *)bluetooth_getname(),bluetooth_recv_state_cb );
						if( ret == pdPASS )
						{
							gaoz_log_debug_printf(INFOR_MODE,"800b","gaoz_ble_drive_data_open Okay! %s\r\n", bluetooth_getname());
						}
					}
					else
					{
						if(( memcmp( ( uint8_t *)bluetooth_getname(), ( uint8_t *)&rsaDa[hex2CombineOne(rsaDa)+2+1] ,rsaDa[hex2CombineOne(rsaDa)+2] ) != 0 )
							|| ( strlen((char *)bluetooth_getname() ) != rsaDa[hex2CombineOne(rsaDa)+2] ))
						{
							bluetooth_setname(&rsaDa[hex2CombineOne(rsaDa)+2+1],rsaDa[hex2CombineOne(rsaDa)+2]);
							gaoz_log_debug_printf(INFOR_MODE,"800b","bt_getname()= %s,%d", bluetooth_getname(),strlen((char *)bluetooth_getname()));
							/*ret = gaoz_ble_drive_data_close( (char *)bluetooth_getname());
							if(ret == pdPASS)
							{
								gaoz_log_debug_printf(INFOR_MODE,"800b","gaoz_ble_drive_data_close  OKay!\r\n");
							}*/
							ret = gaoz_ble_drive_data_open( (char *)bluetooth_getname(),bluetooth_recv_state_cb );
							if( ret == pdPASS )
							{
								gaoz_log_debug_printf(INFOR_MODE,"800b","gaoz_ble_drive_data_open Okay! %s\r\n", bluetooth_getname());
							}
						}
						else
						{
							gaoz_log_debug_printf(INFOR_MODE,"800b","ble name same = %s,%d", bluetooth_getname(),strlen((char *)bluetooth_getname()));
						}
					}
				}
			}
		}
		break;
		case 0x9581:
		{
			patiores_msg.commane = TER_QUERY_RSA;
			patiores_msg.results = pdPASS;
			ret = national808_net_patiores_queue_put(&patiores_msg);
			if(ret < 1)
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9581 fail!\r\n");
			}
			devres_msg.respondcmd = Message_ID;
			devres_msg.respondsn = Message_Serial_Number;
			devres_msg.respondsta = 0;
			ret = national808_net_devres_queue_put(&devres_msg);
			if(ret < 1)
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9581 fail!\r\n");
			}
		}
		break;
		case 0x9582:
		{
			
		}
		break;
		case 0x9584:
		{
			if( (national808_ctrllock_state_get() == CTLOCK_INIT) ||
				(national808_ctrllock_state_get() == CTLOCK_OK))
			{
				patiores_msg.commane = TER_CONTROL_TER_UP_DOWN_WIND;
				patiores_msg.results = pdPASS;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9584 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 0;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_put 9584 fail!\r\n");
				}
	
				if(pMsgBody[0] != 0)
				{
					national808_ctrllock_state_set(CTLOCK_PATIO_WIND);
				}
				if(vehiclect_runing_state_get() == CARCTL_RUNING_INIT)	
				{
					ctlock_msg.lock_type = pMsgBody[0];
					ctlock_msg.lock_res.respondcmd = Message_ID;
					ctlock_msg.lock_res.respondsn = Message_Serial_Number;
					ctlock_msg.lock_res.respondsta = 0; 
					ctlock_msg.lock_err = 0;
					ret = national808_ctlock_queue_put(&ctlock_msg);
					if(ret < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"800b","ctlock_queue_put 9584 fail!\r\n");
					}
				}
				else
				{
					national808_ctrllock_state_set(CTLOCK_OK);
				}
			}
			else
			{
				patiores_msg.commane = TER_CONTROL_TER_UP_DOWN_WIND;
				patiores_msg.results = pdPASS;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9584 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 0;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_put 9584 fail!\r\n");
				}	
			}
		}
		break;
		case 0x9590:
		{
			patiores_msg.commane = TER_QUERY_SYS_PARRMETER;
			patiores_msg.results = pdPASS;
			ret = national808_net_patiores_queue_put(&patiores_msg);
			if(ret < 1)
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9590 fail!\r\n");
			}
			devres_msg.respondcmd = Message_ID;
			devres_msg.respondsn = Message_Serial_Number;
			devres_msg.respondsta = 0;
			ret = national808_net_devres_queue_put(&devres_msg);
			if(ret < 1)
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_put 9590 fail!\r\n");
			}
		}
		break;
		case 0x9594:
		{
			
		}
		break;
		case 0x9635: /*qxwz*/
		{
			uint8_t appkey[100]={0};
			uint8_t appkey_index = 0;
			if((Message_Property == 0) || (Message_Property > 100))
			{
				break;	
			}
			memcpy(appkey,pMsgBody,Message_Property);	
			appkey[Message_Property] = get_chk_xor(appkey,Message_Property);
			ret = file_termpara_write(QXWZKEY,(INT8 *)appkey,Message_Property+1);
			if(ret < 0)
			{
				patiores_msg.commane = TER_CONTROL_TER_QXWZKEY_SET;
				patiores_msg.results = pdFAIL;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9635 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 1;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9635 fail!\r\n");
				}
			}
			else
			{
				appkey_index = 0;
				if((appkey[appkey_index] < QXWZ_CFG_MAX_LEN) && (appkey[appkey_index] != 0))
				{
					appkey_index ++;
					memcpy(qxwz_key_t.app_key,&appkey[appkey_index],appkey[appkey_index-1]);
				}
				gaoz_log_debug_printf(INFOR_MODE,"800b","app_key %s\r\n",qxwz_key_t.app_key);
				appkey_index += appkey[appkey_index-1];
				if((appkey[appkey_index] < QXWZ_CFG_MAX_LEN) && (appkey[appkey_index] != 0))
				{
					appkey_index ++;
					memcpy(qxwz_key_t.app_secret,&appkey[appkey_index],appkey[appkey_index-1]);
				}
				gaoz_log_debug_printf(INFOR_MODE,"800b","app_secret %s\r\n",qxwz_key_t.app_secret);
				HexToAsciiString((char *)qxwz_key_t.device_id,(char *)terminid, 4);
				gaoz_log_debug_printf(INFOR_MODE,"800b","device_id %s\r\n",qxwz_key_t.device_id);
				sprintf((char *)qxwz_key_t.device_type, "%s", QXWZDEVICE_TYPE);
				gaoz_log_debug_printf(INFOR_MODE,"800b","device_type %s\r\n",qxwz_key_t.device_type);
				ret = gaoz_qxwz_inject_cfg_save_flash_write(&qxwz_key_t);
				if(ret == pdPASS)
				{
					patiores_msg.commane = TER_CONTROL_TER_QXWZKEY_SET;
					patiores_msg.results = pdPASS;
					ret = national808_net_patiores_queue_put(&patiores_msg);
					if(ret < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9635 fail!\r\n");
					}
					devres_msg.respondcmd = Message_ID;
					devres_msg.respondsn = Message_Serial_Number;
					devres_msg.respondsta = 0;
					ret = national808_net_devres_queue_put(&devres_msg);
					if(ret < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9635 fail!\r\n");
					}
				}
				else
				{
					patiores_msg.commane = TER_CONTROL_TER_QXWZKEY_SET;
					patiores_msg.results = pdFAIL;
					ret = national808_net_patiores_queue_put(&patiores_msg);
					if(ret < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9635 fail!\r\n");
					}
					devres_msg.respondcmd = Message_ID;
					devres_msg.respondsn = Message_Serial_Number;
					devres_msg.respondsta = 1;
					ret = national808_net_devres_queue_put(&devres_msg);
					if(ret < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9635 fail!\r\n");
					}
				}
			}	
		}
		break;
		case 0x9636:
		{
			patiores_msg.commane = TER_QUERY_QXWZPARA;
			patiores_msg.results = pdPASS;
			ret = national808_net_patiores_queue_put(&patiores_msg);
			if(ret < 1)
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9636 fail!\r\n");
			}
			devres_msg.respondcmd = Message_ID;
			devres_msg.respondsn = Message_Serial_Number;
			devres_msg.respondsta = 0;
			ret = national808_net_devres_queue_put(&devres_msg);
			if(ret < 1)
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9636 fail!\r\n");
			}
		}
		break;
		case 0x9637:
		{
			ret = n808_erase_qxwzkey();
			if(ret == pdPASS)
			{
				patiores_msg.commane = TER_CONTROL_TER_QXWZKEY_CLE;
				patiores_msg.results = pdPASS;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9637 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 0;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9637 fail!\r\n");
				}
			}
			else
			{
				patiores_msg.commane = TER_CONTROL_TER_QXWZKEY_CLE;
				patiores_msg.results = pdPASS;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9637 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 1;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9637 fail!\r\n");
				}
			}
		}
		break;
		case 0x9601:
		{
			ret = n808_match_pkekey(pMsgBody,Message_Property);
			if(ret == pdPASS)
			{
				patiores_msg.commane = TER_QUERY_PKEKEY;
				patiores_msg.results = pdPASS;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9601 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 0;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_put 9601 fail!\r\n");
				}					
			}
			else
			{
				patiores_msg.commane = TER_QUERY_PKEKEY;
				patiores_msg.results = pdFAIL;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					OSI_PRINTFI("national808_net_res_queue_put 9601 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 1;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_put 9601 fail!\r\n");
				}	
			}
		}
		break;
		case 0x9605:
		{
			if((pMsgBody[0] < 1) || (pMsgBody[0] > 4))
			{
				
			}
			else
			{
				ret = n808_save_pkekey(pMsgBody,Message_Property);
				if(ret == pdPASS)
				{
					patiores_msg.commane = TER_CONTROL_TER_PKEKEY;
					patiores_msg.results = pdPASS;
					ret = national808_net_patiores_queue_put(&patiores_msg);
					if(ret < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9605 fail!\r\n");
					}
					devres_msg.respondcmd = Message_ID;
					devres_msg.respondsn = Message_Serial_Number;
					devres_msg.respondsta = 0;
					ret = national808_net_devres_queue_put(&devres_msg);
					if(ret < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_put 9605 fail!\r\n");
					}					
				}
			}
		}
		break;
		case 0x9613:
		{
			if( warmcarled_net_data_write( (uint8_t *)&pMsgBody[2] , char2u16(&pMsgBody[0]) ) == pdPASS )
			{
				patiores_msg.commane = TER_RESPONSE_DATA_DOWN;
				patiores_msg.results = pdPASS;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9613 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 0;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_put 9613 fail!\r\n");
				}	
			}
			else
			{
				patiores_msg.commane = TER_RESPONSE_DATA_DOWN;
				patiores_msg.results = pdFAIL;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_patiores_queue_put 9613 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 1;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_put 9613 fail!\r\n");
				}	
			}
		}
		break;
		case 0x9595:	/*一键启动控制*/
		{
			if( vehicle_engine_start_st_set( Message_Serial_Number, Message_ID, pMsgBody[0] ) == pdPASS )
			{
				patiores_msg.commane = TER_CONTROL_TER_START_ENGINE;
				patiores_msg.results = pdPASS;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{	
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9595 fail!\r\n");
				}	
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 0;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_put 9595 fail!\r\n");
				}
			}
			else
			{
				patiores_msg.commane = TER_CONTROL_TER_START_ENGINE;
				patiores_msg.results = pdPASS;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9595 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 1;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_put 9595 fail!\r\n");
				}
			}
		}
		break;
		case 0x9599:	/*故障码查询*/
			if( vehicle_fault_code_infor_set( pMsgBody[0], pMsgBody[1], 0x00, NULL ) == pdPASS )
			{
				patiores_msg.commane = TER_FAULT_CODE_QUERY;
				patiores_msg.results = pdPASS;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9599 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 0;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_put 9599 fail!\r\n");
				}
			}
			else
			{
				patiores_msg.commane = TER_FAULT_CODE_QUERY;
				patiores_msg.results = pdPASS;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9599 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 1;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_put 9595 fail!\r\n");
				}
			}
		break;
		case 0x9600:	/*故障码清除*/
			patiores_msg.commane = TER_FAULT_CODE_CLEAR;
			patiores_msg.results = pdPASS;
			ret = national808_net_patiores_queue_put(&patiores_msg);
			if(ret < 1)
			{	
				gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9600 fail!\r\n");
			}	
			devres_msg.respondcmd = Message_ID;
			devres_msg.respondsn = Message_Serial_Number;
			devres_msg.respondsta = 0;
			ret = national808_net_devres_queue_put(&devres_msg);
			if(ret < 1)
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_put 9600 fail!\r\n");
			}
		break;
		case 0x9103:
			if( vehicle_maintenance_infor_set( pMsgBody, Message_Property ) == pdPASS )
			{	
				patiores_msg.commane = TER_MAINTENANCE_INFOR_SET;
				patiores_msg.results = pdPASS;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9595 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 0;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_put 9595 fail!\r\n");
				}
			}
			else
			{
				patiores_msg.commane = TER_MAINTENANCE_INFOR_SET;
				patiores_msg.results = pdPASS;
				ret = national808_net_patiores_queue_put(&patiores_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9595 fail!\r\n");
				}
				devres_msg.respondcmd = Message_ID;
				devres_msg.respondsn = Message_Serial_Number;
				devres_msg.respondsta = 1;
				ret = national808_net_devres_queue_put(&devres_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_put 9595 fail!\r\n");
				}
			}
		break;
		case 0x9654:	/*平台下发车辆安全认证KEY*/
			if( vehicle_key_infor_set( pMsgBody ) == pdPASS )
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","Platform sends the security key:[9654]\r\n" );
				if(vehiclect_runing_state_get() == CARCTL_RUNING_INIT)
				{
					vehiclect_runing_state_set(CARCTL_RUNING_KEY_INFOR_SET);/*设置密钥KEY*/
				}
			}
		break;
		case 0x9655:
		{
			vehicle_rv_power_control_set( pMsgBody[0]  );
			patiores_msg.commane = TER_RV_POWER_CTL;
			patiores_msg.results = pdPASS;
			ret = national808_net_patiores_queue_put(&patiores_msg);
			if(ret < 1)
			{	
				gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_res_queue_put 9655 fail!\r\n");
			}	
			devres_msg.respondcmd = Message_ID;
			devres_msg.respondsn = Message_Serial_Number;
			devres_msg.respondsta = 0;
			ret = national808_net_devres_queue_put(&devres_msg);
			if(ret < 1)
			{
				gaoz_log_debug_printf(INFOR_MODE,"800b","national808_net_devres_queue_put 9655 fail!\r\n");
			}
		}
		break;
		default:
        
        break;
    }
	gaoz_fibo_free(tmpDa);
}

/** ****************************************************************************
* @remarks       static uint32_t parse_patio_recv_data( uint8_t *da, uint16_t len )
* @brief        解析平台下发数据
* @param[in]     *da缓存区，len长度
* @param[out]    无
* @return        pdPASS 数据发送成功 pdFAIL 数据发送失败
* @attention     
*******************************************************************************/
static uint32_t parse_patio_recv_data( uint8_t *da, uint16_t len )
{
    uint32_t res = pdFAIL;    
	uint16_t CR_i;
	uint16_t tmpLen, RawDaLen;
	uint16_t CR_i_Start;
	uint16_t iStart, iEnd;	//记录当前包的开始和结束位置

	uint16_t i,j;

	uint8_t *GPRS_Response = da;
	uint16_t AllPac_Len;

	gaoz_log_debug_printf(INFOR_MODE,"800b", "debug 800b da[%d] da[%d] da[%d] da[%d]\r\n",da[0],da[1],da[2],da[3] );
    gaoz_mutex_lock(patio_recv_data_mutex);
	AllPac_Len = len;
    uint8_t *temp = (uint8_t *)gaoz_fibo_malloc(1024*2);
    if (temp == NULL)
    {
        return res;
    }

	if (AllPac_Len == 0)
	{
		gaoz_fibo_free(temp);
		return res;
	}

	CR_i = 0;

	while (CR_i < AllPac_Len)
	{
		CR_i_Start = CR_i;

		if (patio_recv_data.len != 0)	
		{
			//说明上次有半包情况，半包情况，在extr_da中，必然第一个是7E
			memcpy(temp, patio_recv_data.data, patio_recv_data.len);

			//开始找尾
			while (GPRS_Response[CR_i] != 0x7E)
			{
				CR_i ++;
				if (CR_i >= AllPac_Len)
				{
					//极端情况，整包数据，没有结尾的7e
					tmpLen = patio_recv_data.len + CR_i - CR_i_Start;
					//先判断数组不要越界
					if (tmpLen > PATIO_RX_BUF_SIZE)
					{
						//假设收到了外太空信号，不处理
						gaoz_fibo_free(temp);
						return res;
					}

					memcpy(&patio_recv_data.data[patio_recv_data.len], &GPRS_Response[CR_i_Start], CR_i - CR_i_Start);
					patio_recv_data.len = tmpLen;
					gaoz_fibo_free(temp);
					return res;
				}
			}

			//找到尾巴了，把这段数据存入temp数据，之后等待进行转义的处理
			if ( (patio_recv_data.len + CR_i - CR_i_Start + 1) < PATIO_RX_BUF_SIZE )
			{
				memcpy(&temp[patio_recv_data.len], &GPRS_Response[CR_i_Start], CR_i - CR_i_Start + 1);
				//temp中的数据，包括头尾
				RawDaLen = patio_recv_data.len + CR_i - CR_i_Start + 1;
			}
			else
			{
				//temp中的数据，包括头尾
				RawDaLen = 0;
			}

			patio_recv_data.len = 0;
			CR_i ++; //保证下次检查数据，是最新的
		}
		else
		{
			//上一包没有残余数据, 找头
			while (GPRS_Response[CR_i] != 0x7E)
			{
				CR_i ++;
				if (CR_i >= AllPac_Len)
				{
					//极端情况，一包数据，只收到了两个7e中间的 几个字节，暂时不考虑
					gaoz_fibo_free(temp);
					return res;
				}
			}
			iStart = CR_i; //找到了7E头
			//开始找尾
			CR_i ++;
			if (CR_i >= AllPac_Len)
			{
				tmpLen = CR_i - iStart;

				//先判断数组不要越界
				if (tmpLen > PATIO_RX_BUF_SIZE)
				{
					tmpLen = 0;
				}
				//属于残余数据，保存进extr_da
				memcpy(patio_recv_data.data, &GPRS_Response[iStart], tmpLen);
				patio_recv_data.len = tmpLen;
				gaoz_fibo_free(temp);
				return res;
			}

			while (GPRS_Response[CR_i] != 0x7E)
			{
				CR_i ++;
				if (CR_i >= AllPac_Len)
				{
					tmpLen = CR_i - iStart;

					//先判断数组不要越界
					if (tmpLen > PATIO_RX_BUF_SIZE)
					{
						tmpLen = 0;
					}
					//属于残余数据，保存进extr_da
					memcpy(patio_recv_data.data, &GPRS_Response[iStart], tmpLen);
					patio_recv_data.len = tmpLen;
					gaoz_fibo_free(temp);
					return res;
				}
			}
			iEnd = CR_i; //找到了7E end tag

			CR_i ++; //保证下次检查数据，是最新的

			//找到尾巴了，把这段数据存入temp数据，之后等待进行转义的处理
			if ( (iEnd - iStart + 1) < PATIO_RX_BUF_SIZE )
			{
				memcpy(temp, &GPRS_Response[iStart], iEnd - iStart + 1);
				//temp中的数据，包括头尾
				RawDaLen = iEnd - iStart + 1;
			}
			else
			{
				RawDaLen = 0;
			}			
		}

		if (RawDaLen == 0)
		{
			continue;
		}
		//转义
		//不再解析头尾
		RawDaLen --; 
		if (RawDaLen == 1)
		{
			//说明只收到了两个7E，有可能就是中间漏掉一包，为了防止
			//两个7E，我们再重新查找数据，最多丢一包
			CR_i --;
			continue;
		}
		for (i=1,j=0;i<RawDaLen;i++)
		{
			if ( (temp[i] == 0x7D) && (temp[i+1] == 0x02) )
			{
				temp[j++] = 0x7E;
				i++;
			}
			else if ( (temp[i] == 0x7D) && (temp[i+1] == 0x01) )
			{
				temp[j++] = 0x7D;
				i++;
			}
			else
			{
				temp[j++] = temp[i];
			}
		}

		// 计算校验，只有校验OK才可以解析
		if (get_chk_xor(temp, j) != 0)
		{		
			continue;
		}

		//把解析单独弄出去，清晰些
		parsepatio_protocol(temp, j);
        res = pdPASS;
	}
	gaoz_fibo_free(temp);
    gaoz_mutex_unlock( patio_recv_data_mutex );
	// gaoz_log_debug_printf(INFOR_MODE,"800b", "<<<gaoz_mutex_unlock( patio_recv_data_mutex>>>\r\n" );
    return res;
}


/** ****************************************************************************
* @remarks       static uint32_t national808_decrypt_package( uint8_t * pDa, uint16_t * len, uint16_t serailNum )
* @brief         网络数据包解密
* @param[in]     *pDa 数据源地址，serailNum 序列号
* @param[out]    *len 返回的数据长度
* @return        pdPASS 成功，pdFAIL 失败
* @attention     无
*******************************************************************************/
static uint32_t national808_decrypt_package( uint8_t * pDa, uint16_t *len, uint16_t serailNum )
{
	uint8_t tmpDa[16] = { 0 };

	//兼容没有使用加密机制的机器
	if ( taginf.rs[0] != 1 )
	{
		return pdFAIL;
	}

	memcpy(tmpDa, ( uint8_t * )&taginf.rs[1], 16);
	tmpDa[0] ^= (uint8_t)(serailNum >> 8);
	tmpDa[1] ^= (uint8_t)(serailNum);

	aes_decrypt_multi(pDa, *len, tmpDa);
	
	return pdPASS;
}
#if( USER_AES_ENCRYPT_N800 == 1 )
/** ****************************************************************************
* @remarks       void national808_encrypt_package( uint8_t * pDa, uint16_t * len, uint16_t serailNum )
* @brief         网络数据包加密
* @param[in]     *pDa 数据源地址，serailNum 序列号
* @param[out]    *len 返回的数据长度
* @return        pdPASS 成功，pdFAIL 失败
* @attention     加密，只针对消息体部分 不足8字节倍数，补0x00，凑足8字节
*******************************************************************************/
static uint32_t national808_encrypt_package( uint8_t *pDa, uint16_t *len, uint16_t serailNum )
{
	uint16_t startBodyIDX;
	uint16_t newBodyLen;
	uint16_t PacLen;
	uint8_t addLen;
	uint8_t pckMulSta;
	uint8_t tmpDa[16];

	//兼容没有使用加密机制的机器
	if (taginf.rs[0] != 1)
	{
		return pdFAIL;
	}
	
	PacLen = *len;

	//心跳类的没有消息体，长度=0，下面程序会报错
	if (PacLen <= 0x0d)
	{
		return pdFAIL;
	}

	//对分包项的检查
	pckMulSta = pDa[2] & 0x20;

	if (pckMulSta == 0)
	{
		startBodyIDX = 12;
	}
	else
	{
		startBodyIDX = 16;
	}
	if (PacLen < startBodyIDX)
	{
		return pdFAIL;
	}

	//让新的msg body len 补齐16的倍数
	newBodyLen = PacLen - startBodyIDX - 1;
	addLen = newBodyLen % 16;
	if (addLen != 0)
	{
		addLen = 16 - addLen;
	}
	memset(&pDa[startBodyIDX + newBodyLen], 0, addLen);
	newBodyLen += addLen;

	memcpy(tmpDa, ( uint8_t * )&taginf.rs[1], 16);

	tmpDa[0] ^= (uint8_t)(serailNum >> 8);
	tmpDa[1] ^= (uint8_t)(serailNum);
	aes_encrypt_multi(&pDa[startBodyIDX], newBodyLen, tmpDa);

	pDa[2] &= 0xF8;
	pDa[2] |= 0x08;
	pDa[2] |= (uint8_t)(newBodyLen >> 8) & 0x03;
	pDa[3] = (uint8_t)newBodyLen;

	PacLen += addLen;
	pDa[PacLen - 1] = get_chk_xor(pDa, PacLen - 1);
	(*len) = PacLen;

	return pdPASS;
}
#endif
/** ****************************************************************************
* @remarks       static uint32_t national808_decrypt_package_shell( uint8_t* pDa, uint16_t* len )
* @brief         网络数据包外层数据包解密
* @param[in]     *pDa 数据源地址
* @param[out]    *len 返回的数据长度
* @return        pdPASS 成功，pdFAIL 失败
* @attention     无
*******************************************************************************/
static uint32_t national808_decrypt_package_shell( uint8_t* pDa, uint16_t* len )
{
	#define  gloAESKey	"\x0C\xF5\x82\xFC\x24\x71\xDC\x13\x53\x8B\xEA\x2F\xB6\x85\xA6\xFD"
	#define  BJ_TIMESTAMP ( 946656000 ) /*2000-01-01 00:00:00 时间戳*/
	
	uint8_t tmpDa[16];
	uint8_t newData[1024 + 30];
	uint16_t i;
	//u16 idx;
	uint8_t tmpBit;
	uint16_t dataLen, dataInLen;
	uint16_t cmd;
	uint32_t timeStamp, timeStampL;
	
	dataInLen = *len;
	*len = 0;	//先假设数据是错误的
	/*if (get_chk_xor(pDa, dataInLen) != 0)
	{
		return;
	}*/
	//循环右移1位
	tmpDa[0] = pDa[2];
	tmpBit = 0x80 & (tmpDa[0]<<7);
	tmpDa[0] = 0x7F & (tmpDa[0] >> 1);
	tmpDa[0] |= tmpBit;
	//循环左移1位
	tmpDa[1] = pDa[3];
	tmpBit = 0x01 & (tmpDa[1] >> 7);
	tmpDa[1] = 0xFE & (tmpDa[1] << 1);
	tmpDa[1] |= tmpBit;
	//确定长度
	dataLen = (tmpDa[0] << 8) | tmpDa[1];
	dataLen -= 1;	//去掉校验部分

	if((dataLen > 1024+20) || (dataLen > (dataInLen-5)))
	{
		return pdFAIL;
	}

	//这样写，实际是为了防止秘钥直接明文暴露在程序中。
	memcpy(tmpDa, gloAESKey, 16);
	for (i = 0; i < 16;i++)
	{
		tmpDa[i] ^= 0x5A;
	}

	//开始解密
	memcpy(newData, &pDa[4], dataLen);
	aes_decrypt_multi(newData, dataLen, tmpDa);
	//先判断时间戳是否正确
	//关于通用应答的，不判断时间戳，鉴权应答的也不判断时间戳。
	timeStamp = (newData[0] << 24) | 
				(newData[1] << 16) |
				(newData[2] << 8) |
				newData[3];

	cmd = (newData[4] << 8) | newData[5];

	//除去通用应答、注册应答、鉴权应答不判断时间戳，其它都判断。
	if ((cmd != 0x8100) && (cmd != 0x9501))
	{
		gaoz_rtc_sys_get( RTC_TIM_TIMESTAMP, (uint32_t *)&timeStampL);
		timeStampL = timeStampL - BJ_TIMESTAMP;
		
		if (timeStamp > timeStampL)
		{
			if ((timeStamp - timeStampL) > 3600)
			{
				//时间戳错误，重新鉴权
				//lets_re_auth_after5sec();
				//return pdFAIL;
			}
		}
		else
		{
			if ((timeStampL - timeStamp) > 3600)
			{
				//时间戳错误，重新鉴权
				//lets_re_auth_after5sec();
				//return pdFAIL;
			}
		}
	}
	
	//程序走到这里说明，以上校验判断都是正确的，下面开始把内部的报文，写入新数组
	//-9： 两个字节的5001，两个字节的长度，4个字节的时间，1个字节的校验
	memcpy(pDa, &newData[4], dataInLen-9);	

	*len = dataInLen - 9;

	return pdPASS;
}
#if( USER_AES_ENCRYPT_N800 == 1 )
/** ****************************************************************************
* @remarks       static uint32_t national808_encrypt_package_shell( uint8_t* pDa, uint16_t* len )
* @brief         网络数据包二次加密
* @param[in]     *pDa 数据源地址
* @param[out]    *len 返回的数据长度
* @return        pdPASS 成功，pdFAIL 失败
* @attention     加密，第二次加密 不足8字节倍数，补0x00，凑足8字节
*******************************************************************************/
static uint32_t national808_encrypt_package_shell( uint8_t* pDa, uint16_t* len )
{
	#define  gloAESKey	"\x0C\xF5\x82\xFC\x24\x71\xDC\x13\x53\x8B\xEA\x2F\xB6\x85\xA6\xFD"
	#define  BJ_TIMESTAMP ( 946656000 ) /*2000-01-01 00:00:00 时间戳*/
	
	uint8_t addLen;
	//u8 pckMulSta;
	uint8_t tmpDa[16];
	uint8_t newData[1024+30];
	
	uint16_t startBodyIDX;
	uint16_t newBodyLen;
	uint16_t PacLen;
	uint16_t i;
	uint16_t idx;
	uint8_t tmpBit;
	uint32_t ulTmp;

	PacLen = *len;
	if ((PacLen > 1024) || (PacLen == 0))
	{
		return pdFAIL;
	}

	//写入特殊命令字
	memcpy(newData, "\x50\x01", 2);
	idx = 2;

	//让新的msg body len 补齐16的倍数
	newBodyLen = PacLen - 1 + 4;	//先去掉一个校验， 增加时间戳
	addLen = newBodyLen % 16;
	if (addLen != 0)
	{
		addLen = 16 - addLen;
	}

	//写入长度
	newBodyLen += addLen+1;
	if (newBodyLen > 1034)
	{
		return pdFAIL;
	}

	//循环左移1位
	newData[idx] = (u8)(newBodyLen>>8);
	tmpBit = 0x01&(newData[idx]>>7);
	newData[idx] = (newData[idx] << 1) & 0xFE;
	newData[idx] |= tmpBit;
	idx++;

	//循环右移1位
	newData[idx] = (u8)(newBodyLen);
	tmpBit = 0x80 & (newData[idx]<<7);
	newData[idx] = 0x7F & (newData[idx] >> 1);
	newData[idx] |= tmpBit;
	idx++;

	//时间戳
	startBodyIDX = idx;
	gaoz_rtc_sys_get( RTC_TIM_TIMESTAMP, (uint32_t *)&ulTmp);
	ulTmp = ulTmp - BJ_TIMESTAMP;

	newData[idx++] = (u8)(ulTmp>>24);
	newData[idx++] = (u8)(ulTmp >> 16);
	newData[idx++] = (u8)(ulTmp >> 8);
	newData[idx++] = (u8)(ulTmp);

	//把原来的消息头和消息体赋值入数组,
	memcpy(&newData[idx], pDa, PacLen-1);
	idx += PacLen-1;

	//简单方法，防止越界
	if (idx > 1040)
	{
		return pdFAIL;
	}

	//写入填充报文
	memset(&newData[idx], 0xA0, addLen);
	idx += addLen;

	//秘钥简单转换一下
	memcpy(tmpDa, gloAESKey, 16);
	for (i = 0; i < 16; i++)
	{
		tmpDa[i] ^= 0x5A;
	}
	//加密了
	aes_encrypt_multi(&newData[startBodyIDX], idx-startBodyIDX, tmpDa);
	//可以开始计算校验了
	newData[idx] = get_chk_xor(newData, idx);
	idx++;

	if (idx < 1054)
	{
		memcpy(pDa, newData, idx);
		(*len) = idx;
	}
	else
	{
		(*len) = 0;
	}

	return pdPASS;
}
#endif

/** ****************************************************************************
* @remarks       static void national808_ota_handle_task(void)
* @brief         升级流程管理（熄火+上锁允许升级）
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     在系统启动后进行创建
*******************************************************************************/
static void national808_ota_handle_task(void)
{
	#define FOTA_CHECK_STATE_TIME ( 1000 )	/*检测FOTA升级状态1S*/
	uint8_t net_run_st = 0;

	gaoz_mon_reg_task_dog( 60 * GAOZ_TICK_PERIOD_S ,(uint8_t *)NAT808_OTATASK_NAME ,TASK_SEM_YES);
	for( ;; )
	{
	#if 1
		gaoz_mon_reset_task_dog();
		net_module_run_state_get( MOD_STATE ,(uint8_t *)&net_run_st );     
		if( net_run_st != MODULE_NET_OPEN )				/*检测网络是否可用，当网络正常时才可以进行升级状态的检测*/
		{
			gaoz_task_sleep( FOTA_CHECK_STATE_TIME );
			continue;
		}
		if( terota_handle.upgrade_type != OTA_INIT )	/*检测当前的升级状态*/
		{
			fota_manage(&terota_handle);
		}
		gaoz_task_sleep( FOTA_CHECK_STATE_TIME );
	#else
        gaoz_mon_reset_task_dog();
		if( (socket_state_1.create_socket_state != SOCKET_LINK_CREATE_OK ) || (n808_netready != NET_READY_OK))
		{
			gaoz_task_sleep( 100 );
			continue;
		}
		/* 熄火+上锁 */
		//if((get_vehicleAcc_st() == 0x00) && (get_vehicleLock_st() == 0x00))
		if( 1 )
		{
			if( terota_handle.upgrade_type != OTA_INIT )
			{
				fota_manage(&terota_handle);
			}
			else
			{
				gaoz_task_sleep( 1000 );
			}
		}
		else
		{
			gaoz_task_sleep( 1000 );
		}
	#endif	
	}
}

/** ****************************************************************************
* @remarks       static void national_net_run_para_init( void )
* @brief         网络运行参数初始化
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     在系统启动后进行创建
*******************************************************************************/
static void national808_net_run_para_init( void )
{
	int ret = 0;
	national_808_relay_state = 0;
    national808_runing_st = TER_RUNING_INIT;
    national808_response = PLAT_NO_RESPONSE;
	national808_ctlock = CTLOCK_INIT;
	national_808_ip_addr_t = EXTERNAL_IP_ADDR;
	national808_data_st.send_data  = (uint8_t *)gaoz_fibo_malloc( UNIT_FLASH_DATA_LEN );
    if( national808_data_st.send_data == NULL )
    {
		while(1); /*创建失败*/
	}
	
	reset_reason_get(&national808_reset_reason);//获取设备重启的原因
	national808_data_st.send_datalen = 0;
	//national808_data_st.send_st = N808_SEND_INIT;
	national808_send_state = N808_SEND_INIT;
	/* 平台缓存 */
	patio_recv_data_mutex_create();
    patio_recv_data.data = (uint8_t *)gaoz_fibo_malloc( PATIO_RX_BUF_SIZE );
    if(patio_recv_data.data == NULL)
	{
		while(1); /*创建失败*/
	}
    memset((uint8_t *)patio_recv_data.data, 0x00 , PATIO_RX_BUF_SIZE);
    patio_recv_data.len = 0;
	/*OTA check*/
	fota_checkversion();
	/*qxwz key manger*/
	n808_manger_qxwzkey();
	/*pkekey*/
	ret = n808_read_pkekey();
	if(ret != pdPASS)
	{
		gaoz_log_debug_printf(INFOR_MODE,"800b","n808_read_pkekey fail!\n");
	}
	/*err code*/
	gerr_code = (uint8_t *)gaoz_fibo_malloc( ERR_CODE_CONFIG );
	if(gerr_code == NULL)
	{
		while(1); /*创建失败*/
	}
	memset((uint8_t *)gerr_code, 0x00 , ERR_CODE_CONFIG);

	memset((uint8_t *)&socket_state_1 , 0x00 , sizeof(socket_state_t));
	memset((uint8_t *)&socket_handle_1 , 0x00 , sizeof(socket_handle_s));
	socket_default( &socket_handle_1 );
}

/** ****************************************************************************
* @remarks       uint32_t national808_net_ctrl_infor_set( national_run_state_e st )
* @brief         设置平台命令发送消息体数据
* @param[in]     st 控制状态
* @param[out]    无
* @return        pdFAIL - 设置失败，pdPASS - 设置成功
* @attention     无
*******************************************************************************/
uint32_t national808_net_ctrl_infor_set( uint8_t st )
{
	uint32_t i = 0, ret = pdFAIL;

	if( national_808_ctrl_infor.count >= NATIONAL_CTRL_INFOR_NUM )
	{
		return pdFAIL;
	}
	/*检索缓存中是否已经保存了控制属性相同的数据*/
	for( i = 0; i < NATIONAL_CTRL_INFOR_NUM; i ++ )
	{
		if( national_808_ctrl_infor.state[i] == st )
		{
			ret = pdPASS;
			break;
		}
	}
	/*缓存中不存在属性相同的控制数据，重新设置数据。计数器加1*/
	if( ret != pdPASS )
	{
		for( i = 0; i < NATIONAL_CTRL_INFOR_NUM; i ++ )
		{
			if( national_808_ctrl_infor.state[i] == TER_RESPONSE_INIT )
			{
				national_808_ctrl_infor.state[i] = st;
				national_808_ctrl_infor.count++;
				ret = pdPASS;
				break;
			}
		}
	}

	return ret;
}

/** ****************************************************************************
* @remarks       uint32_t national808_net_ctrl_infor_get( national_run_state_e st )
* @brief         获取平台命令发送消息体数据
* @param[in]     
* @param[out]    *st 控制状态指针 
* @return        pdFAIL - 获取失败，pdPASS - 获取成功
* @attention     无
*******************************************************************************/
uint32_t national808_net_ctrl_infor_get( uint8_t *st )
{
	uint32_t i = 0, ret = pdFAIL;

	if( national_808_ctrl_infor.count == 0 )
	{
		return pdFAIL;
	}
	*st = TER_RESPONSE_INIT;
	for( i = 0; i < NATIONAL_CTRL_INFOR_NUM; i ++ )
	{
		if( national_808_ctrl_infor.state[i] != TER_RESPONSE_INIT )
		{
			*st = national_808_ctrl_infor.state[i];
			national_808_ctrl_infor.state[i] = TER_RESPONSE_INIT;
			national_808_ctrl_infor.count --;
			ret = pdPASS;
			break;
		}
	}
	
	return ret;
}

/** ****************************************************************************
* @remarks       void national_808_create_task( unsigned portBASE_TYPE uxPriority )
* @brief         808国标任务
* @param[in]     uxPriority 优先级
* @param[out]    无
* @return        无
* @attention     在系统启动后进行创建
*******************************************************************************/
void national_808_create_task( unsigned portBASE_TYPE uxPriority )
{
	file_termpara_init();
	fota_init();
	national808_net_run_para_init();
	national808_socket_semaphore_create();
	national808_net_patiores_queue_create();
	national808_net_devres_queue_create();
	national808_ctlock_queue_create();
	national808_ctlock_res_queue_create();
	national808_upgrade_queue_create();
	gaoz_thread_create(national808_net_st_check_task, "net_st_check", 1024*4, NULL, OSI_PRIORITY_NORMAL);
	gaoz_thread_create(national808_send_data_handle_task, NAT808_SENDTASK_NAME, 1024*10, NULL, uxPriority);
	gaoz_thread_create(national808_recv_data_handle_task, NAT808_RECVTASK_NAME, 1024*10, NULL, uxPriority);
	gaoz_thread_create(national808_ota_handle_task, NAT808_OTATASK_NAME, 1024*16, NULL, uxPriority);
	mangpatio_create_task(uxPriority);	/*启动辅助网络平台*/
}
